Hi, I am trying to put a varible(@MemUnST) in the following statement and I am not sure if this can be done thee way I have it below does not work. The execute part wprks but the IF Not EXISTS part is not, and I know it is because of the varible. If it can be done can someone tell me how please? Thank you
My code IF Not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].' + @MemUnST + ' ') AND name =
N'idx_Mem_Rel_cd_Subscib_Nbr') Begin Exec ('CREATE NONCLUSTERED INDEX [idx_Mem_Rel_cd_Subscib_Nbr] ON [dbo].[Members_UNET_' + @in_st + ']' + '([Mem_Rel_Cd]
Here I want it to create an index if it does nto exist. However, when I test it, with the index on there, it goes to the next line and trys to create it; and naturly comes back with: The operation failed because an index or statistics with name 'idx_Mem_Rel_cd_Subscib_Nbr' already exists on table 'dbo.Members_UBET_CA'.
print out whatever the concatenated strings resolve to when the variables are populated. Then it will probably be obvious to you what the problem is. Do that for both the IF EXISTS condition as well as the CREATE INDEX statement.