Skip to main content
formatted code
Source Link
Nick Chammas
  • 14.8k
  • 17
  • 76
  • 123

Under "Desired Output", the T-SQL going to the server becomes:

SELECT '@@servername' AS worked

SELECT '@@servername' AS worked

Putting single-quotes around @@servername@@servername makes it a string literal and will not be replaced with the actual name, which is why you are seeing @@servername@@servername as the value.

If you're looking to display the server name, remove the single-quotes, making your T-SQL:

SELECT @@servername AS worked

SELECT @@servername AS worked

I'm not entirely clear I understand the question, but this is how you would get what's in your "Desired Output".

Under "Desired Output", the T-SQL going to the server becomes:

SELECT '@@servername' AS worked

Putting single-quotes around @@servername makes it a string literal and will not be replaced with the actual name, which is why you are seeing @@servername as the value.

If you're looking to display the server name, remove the single-quotes, making your T-SQL:

SELECT @@servername AS worked

I'm not entirely clear I understand the question, but this is how you would get what's in your "Desired Output".

Under "Desired Output", the T-SQL going to the server becomes:

SELECT '@@servername' AS worked

Putting single-quotes around @@servername makes it a string literal and will not be replaced with the actual name, which is why you are seeing @@servername as the value.

If you're looking to display the server name, remove the single-quotes, making your T-SQL:

SELECT @@servername AS worked

I'm not entirely clear I understand the question, but this is how you would get what's in your "Desired Output".

Source Link
Pavel
  • 11
  • 1

Under "Desired Output", the T-SQL going to the server becomes:

SELECT '@@servername' AS worked

Putting single-quotes around @@servername makes it a string literal and will not be replaced with the actual name, which is why you are seeing @@servername as the value.

If you're looking to display the server name, remove the single-quotes, making your T-SQL:

SELECT @@servername AS worked

I'm not entirely clear I understand the question, but this is how you would get what's in your "Desired Output".