Pretty new to SQL so I'm looking for the correct way of looping. What I mean is I have a small part of a statement:
,CASE WHEN [PN1] = NULL THEN ' ' ELSE [PN1] END
** lot's more **
Now in the language I know I could do something like this - where the %x% just substitutes the x value:
For x = 1 to 20
,CASE WHEN [PN%x%] = NULL THEN ' ' ELSE [PN%x%] END
** lot's more **
Next
What I have is 20 full statements of the exact same code, just incrementing the part number. Seems there has to be a more efficient way.
Help is very much appreciated!
,CASE WHEN [PN1] = NULL THEN ' ' ELSE [PN1] END
** lot's more **
Now in the language I know I could do something like this - where the %x% just substitutes the x value:
For x = 1 to 20
,CASE WHEN [PN%x%] = NULL THEN ' ' ELSE [PN%x%] END
** lot's more **
Next
What I have is 20 full statements of the exact same code, just incrementing the part number. Seems there has to be a more efficient way.
Help is very much appreciated!