When i do this
declare @cmd nvarchar(50)
set @cmd ='SELECT category_id FROM tbl_BHMCategoryMaster '
exec(@cmd)
query executes properly.
But When I do this
declare @cmd nvarchar(50)
set @cmd ='SELECT [category_id],[category_name],[Basic],[Dimension],[In_Out],[ProfileHand],[Glass],[Hinge],[Edgeband] FROM [tbl_BHMCategoryMaster] '
exec(@cmd)
I get this error and i have no clue what i am doing wrong
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string 'Dime'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Dime'.
But again when i tried this
exec('SELECT [category_id],[category_name],[Basic],[Dimension],[In_Out],[ProfileHand],[Glass],[Hinge],[Edgeband] FROM [tbl_BHMCategoryMaster]')
it worked properly.
There may be many alternative to this but i want to know the problem in detail so that i don't face it next time. If anyone can put some light it will be of great help. Thanks :)
nvarcharneeds to be bigger than(50)