Stored procedure
-
Hi guys, I am executing a stored procedure from my webservices, i would like this store procedure to check is a userid exist and if it does then i would like to return a value saying so. Here is a quick proc...i don't know how to carry on from here.
USE [reportserver]
GO--Create the Procedure
CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10), @RowCount VARCHAR(10) output)
AS
BEGIN
IF EXISTS(SELECT * FROM [UserProfile] WHERE [userid] = @userid)
BEGIN
RETURN @RowCount = 'Exists'
END
ELSE
BEGIN
RETURN @RowCount = 'NotExists'
END
ENDbut it gives me an error: 'Incorrect syntax near '=' Any help please?? Thanks, Morg
-
Hi guys, I am executing a stored procedure from my webservices, i would like this store procedure to check is a userid exist and if it does then i would like to return a value saying so. Here is a quick proc...i don't know how to carry on from here.
USE [reportserver]
GO--Create the Procedure
CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10), @RowCount VARCHAR(10) output)
AS
BEGIN
IF EXISTS(SELECT * FROM [UserProfile] WHERE [userid] = @userid)
BEGIN
RETURN @RowCount = 'Exists'
END
ELSE
BEGIN
RETURN @RowCount = 'NotExists'
END
ENDbut it gives me an error: 'Incorrect syntax near '=' Any help please?? Thanks, Morg
Here's one way:
USE [reportserver]
GO--Create the Procedure
CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10))
AS
BEGIN
declare @RowCount varchar(10)IF EXISTS(SELECT \* FROM \[UserProfile\] WHERE \[userid\] = @userid) BEGIN set @RowCount = 'Exists' END ELSE BEGIN set @RowCount = 'NotExists' END select @RowCount as Counter
END
me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven
-
Here's one way:
USE [reportserver]
GO--Create the Procedure
CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10))
AS
BEGIN
declare @RowCount varchar(10)IF EXISTS(SELECT \* FROM \[UserProfile\] WHERE \[userid\] = @userid) BEGIN set @RowCount = 'Exists' END ELSE BEGIN set @RowCount = 'NotExists' END select @RowCount as Counter
END
me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven
Thanks man, that was great help
-
Hi guys, I am executing a stored procedure from my webservices, i would like this store procedure to check is a userid exist and if it does then i would like to return a value saying so. Here is a quick proc...i don't know how to carry on from here.
USE [reportserver]
GO--Create the Procedure
CREATE PROCEDURE FindCurrentUser(@userid VARCHAR(10), @RowCount VARCHAR(10) output)
AS
BEGIN
IF EXISTS(SELECT * FROM [UserProfile] WHERE [userid] = @userid)
BEGIN
RETURN @RowCount = 'Exists'
END
ELSE
BEGIN
RETURN @RowCount = 'NotExists'
END
ENDbut it gives me an error: 'Incorrect syntax near '=' Any help please?? Thanks, Morg
I wouldn't use rowCount since it is a reserved word. Also I think you are making it more difficult on yourself by requiring hard coded strings. Hard coded strings for program control flow are bad. All you need is this: select count([userid]) from [userprofile] where [userid]=@userID Then in your C# you can just check for > 0.