Solved

defining a variable in stored procedure in SQL Server and MySQL

Posted on 2012-04-06
10
564 Views
Last Modified: 2012-04-15
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
Comment
Question by:akohan
  • 3
  • 3
10 Comments
 
LVL 10

Accepted Solution

by:
plummet earned 250 total points
ID: 37817023
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
 

Author Comment

by:akohan
ID: 37817088
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
 
LVL 10

Expert Comment

by:plummet
ID: 37817124
You just have the SQL print command but you can concatenate strings with a +

eg

Print 'This is the result: ' + @myRight
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 18

Assisted Solution

by:lludden
lludden earned 250 total points
ID: 37817302
SQL 2012 introduces a FORMAT command, but in prior versions formatting is considered something left to the UI layer.
0
 

Author Comment

by:akohan
ID: 37823951
Thanks.
0
 
LVL 10

Expert Comment

by:plummet
ID: 37824582
Hi Akohan

I kind of thought my solution was the one that helped with your original question, but no points? :-(
0
 

Author Comment

by:akohan
ID: 37847661
I see! how can I fix it?

Thanks for letting me know.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now