Why such limitation ? "Subqueries are not allowed in this context. Only scalar expressions are allowed."

  • HI Experts,

    Found that, if I want to pass the string "select @@servername" in the print statement, it throws error as:=

    Msg 1046, Level 15, State 1, Line 3

    Subqueries are not allowed in this context. Only scalar expressions are allowed.

    Msg 1046, Level 15, State 1, Line 28

    Subqueries are not allowed in this context. Only scalar expressions are allowed.

    declare @account_name nvarchar(400) = 'Mail Account';

    IF exists (select * from msdb.dbo.sysmail_account where name = @account_name)

    PRint 'Database Mail Account ' + quotename (@account_name) + 'is already setup in the Server:= ' + (select @@servername);

    What's wrong here? I mean why such restriction? In such queries results will be only 1 so it does not violate the SET operation. correct??

    Thanks.

  • you don't need (select @@server) just use (@@server)

    Alex S
  • I guess the limitation comes because the development team has no interest on creating additional functionality to PRINT. Why would they?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Ohh you are right, using @@servername alone helps....thnx.. hard to remember everything together.

    Thnx much!!!!!

    Thanks.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply