defining a variable in stored procedure in SQL Server and MySQL

Hello,

I'm looking at http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
and since I'm using SQL Server so need to know what is the equivalent of
SELECT @myRight := rgt FROM nested_category
--WHERE name = 'TELEVISIONS';

Open in new window


in SQL Server.

Thanks,
ak
akohanAsked:
Who is Participating?
 
plummetConnect With a Mentor Commented:
It should be:

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

SELECT @myRight = rgt FROM nested_category
--WHERE name = 'TELEVISIONS'

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
0
 
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?

Thanks.
0
 
plummetCommented:
You just have the SQL print command but you can concatenate strings with a +

eg

Print 'This is the result: ' + @myRight
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

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

Thanks for letting me know.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.