Can anyone help me figure this out? Why can I not use this variable.
I get this error for the second one I try: Server: Msg 170, Level 15, State 1, Line 31
Line 31: Incorrect syntax near '@NewICDB_NAME'.
DECLARE @curName VARCHAR(200)
DECLARE @NewICDB_NAME VARCHAR(200)
SET @curName = "Master" <-- I just hardcoded this for this example. This usually varies.
SET @NewICDB_NAME = 'SELECT * FROM ' + @curName + '.dbo.IC0001'
--> Error here
I tried ->IF Not EXISTS (EXEC(@NewICDB_NAME))
I tried ->IF Not EXISTS (@NewICDB_NAME)
BEGIN
SELECT 'The column does not exist'
END
ELSE BEGIN
SELECT 'The column exists'
END
I get this error for the second one I try: Server: Msg 170, Level 15, State 1, Line 31
Line 31: Incorrect syntax near '@NewICDB_NAME'.
DECLARE @curName VARCHAR(200)
DECLARE @NewICDB_NAME VARCHAR(200)
SET @curName = "Master" <-- I just hardcoded this for this example. This usually varies.
SET @NewICDB_NAME = 'SELECT * FROM ' + @curName + '.dbo.IC0001'
--> Error here
I tried ->IF Not EXISTS (EXEC(@NewICDB_NAME))
I tried ->IF Not EXISTS (@NewICDB_NAME)
BEGIN
SELECT 'The column does not exist'
END
ELSE BEGIN
SELECT 'The column exists'
END