Never had a good reason to do this up until now, but if you need to get a value from a generated sql string, there are a few hoops you must jump through. Example:
declare @table varchar(20) ,@username varchar(30) –can't use double quotes w/out thisSET QUOTED_IDENTIFIER OFF –set your variablesselect @table = 'tblcustomers' ,@username = 'webmaster' –create a temp table to hold your valuecreate table #temp (field varchar(50)) –insert the value into temp tableinsert into #tempexec ('select email from ' + @table + ' where username = “' + @username + '”') –voilaselect field from #temp drop table #temp
Reference: Getting Creative with EXEC and EXEC()











No Responses
+
#