1

I have discovered that when I run a CTE in a query window it must have the leading ; but if I am going to run a CTE in a stored procedure it does not need the ;

To me, it would be needed in both places or neither place. Why is this punctuation need in one area and not the other?

Hannah Vernon
  • 70,928
  • 22
  • 177
  • 323
Yohan Greenburg
  • 239
  • 4
  • 9

1 Answers1

1

It's not that a CTE needs a leading ;, but that the statement before must end with a ;.

If the statement with the CTE is the first statement in a batch (or the first statement in your SP), then there's no statement before it to end with a ;

There's a StackOverflow question about it with more detail.

Thomas Rushton
  • 1,134
  • 1
  • 10
  • 11