2

I have a series of datetime variables that need to be referenced, and the key to which variable needs referencing is reached by using substring on another field. I can create the name of the variable as a string using string manipulation, something like this:

'@' + SUBSTRING(field, CHARINDEX(',', field) + 2, LEN(field) - CHARINDEX(',', field) + 1) + 'start'

Is there a way to get SQL to recognize that this is the name of one of my variables? Some kind of function to convert the string?

Tristan
  • 3,301
  • 8
  • 22
  • 27
Corey
  • 37
  • 2
  • Can you post the input and output you expect ? – Ajay Jan 14 '16 at 17:36
  • 1
    You can only do this by passing the variable name into dynamic SQL, and to do that you need to pass the variable reference into an `EXECUTE sp_executesql` call. See the links in the comments above. – Kirk Broadhurst Jan 14 '16 at 17:39

0 Answers0