Link to home
Start Free TrialLog in
Avatar of cheryl9063
cheryl9063Flag for United States of America

asked on

What is wrong with this Case statement?

I have function that will return an integer however I need to do some set up before hand.. I'm trying to populate a table variable based on if the paramater passed into the function(@loginID) is null or not.. My Case and my else is being highlighted as invalid syntax.. What is it?
Declare @UserGroup table(UserGroupID int)
 	CASE 
	WHEN @LoginID is not null
	THEN	
	Insert into @UserGroup
		Select UserGroupID from UserGroup_login
		Where LoginID = 103
    ELSE
    Insert into @UserGroup
		Select UserGroupID from UserGroup_login
		Where UserGroupID = @UserGroupID

Open in new window

Avatar of knightEknight
knightEknight
Flag of United States of America image

An "IF" structure is more appropriate here:

Declare @UserGroup table(UserGroupID int)
        IF @LoginID is not null
        Insert into @UserGroup
                Select UserGroupID from UserGroup_login
                Where LoginID = 103
        ELSE
        Insert into @UserGroup
                Select UserGroupID from UserGroup_login
                Where UserGroupID = @UserGroupID

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial