August 26, 2010 at 7:53 am
Can someone please rectify the syntax error in below code in second line:
SELECT @groupname = 'domname\userid'
CREATE USER @groupname FOR LOGIN @groupname
When i hover the mouse over @groupname in second line it says : Incorrect syntax, expecting ID or QUOTED_ID
August 26, 2010 at 7:58 am
i don't think the CREATE USER command allows variables; you'd have to switch to dynamic SQL instead:
declare @groupname varchar(50),
@sql varchar(1000)
SELECT @groupname = 'domname\userid'
SET @sql ='CREATE USER ' + @groupname + ' FOR LOGIN ' + @groupname
EXEC(@sql)
Lowell
August 26, 2010 at 8:00 am
Would need to be dynamic SQL, e.g.
DECLARE @sql AS VARCHAR(MAX)
SELECT @groupname = 'domname\userid'
SET @sql = 'CREATE USER ' + @groupname + ' FOR LOGIN ' + @groupname
EXEC (@sql)
Damnit Lowell! 😛
August 26, 2010 at 8:02 am
skcadavre (8/26/2010)
Damnit Lowell! 😛
we cross post each others same answers just a bit too often 🙂
Lowell
August 26, 2010 at 8:05 am
Lowell (8/26/2010)
we cross post each others same answers just a bit too often 🙂
I'm beginning to think I should reload the page before posting 😛
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply