I need some help with how SQL works. Trying to get an auto-salutation to be generated from data entered in the Gen_Tables.
My thinking was that we could put a SQL expression into the description column in Gen_Tables and then use that as a string in a query, but it does not recognize it as SQL, only as a string.
E.G. the value in the field is: Name.FIRST_NAME+' '+Name.LAST_NAME
Store that value in a variable @value
I was hoping I could use that in a query like this: SELECT @value from Name where ID=’10000’
However that select statement just returns the string “Name.FIRST_NAME+' '+Name.LAST_NAME”
Know any way to tell SQL to recognize that as an expression, not a string?
You'll need to construct the
You'll need to construct the whole query as dynamic sql and pass it to sp_executesql:
Note that you want to be really, really careful about what you pass to this and how; see http://www.sommarskog.se/dynamic_sql.html for a more complete discussion.