• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

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
0
akohan
Asked:
akohan
  • 3
  • 3
2 Solutions
 
plummetCommented:
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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
lluddenCommented:
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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now