defining a variable in stored procedure in SQL Server and MySQL


I'm looking at
and since I'm using SQL Server so need to know what is the equivalent of
SELECT @myRight := rgt FROM nested_category

Open in new window

in SQL Server.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It should be:

Declare @myRight varchar  -- or Int, or Numeric, or whatever it ought to be

SELECT @myRight = rgt FROM nested_category

Open in new window

I'm assuming the where clause is remarked as you don't need it, but of course removing the -- will make it operable again.

I hope that helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
akohanAuthor Commented:
right ... thank you!

do we have any things like format specifier as we have in C?
sprintf("some string %i , %s", intVar1, StringVar2);

Any idea?

You just have the SQL print command but you can concatenate strings with a +


Print 'This is the result: ' + @myRight
CEOs need to know what they should worry about

Nearly every week during the past few years has featured a headline about the latest data breach, malware attack, ransomware demand, or unrecoverable corporate data loss. Those stories are frequently followed by news that the CEOs at those companies were forced to resign.

SQL 2012 introduces a FORMAT command, but in prior versions formatting is considered something left to the UI layer.
akohanAuthor Commented:
Hi Akohan

I kind of thought my solution was the one that helped with your original question, but no points? :-(
akohanAuthor Commented:
I see! how can I fix it?

Thanks for letting me know.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.