Solved

defining a variable in stored procedure in SQL Server and MySQL

Posted on 2012-04-06
10
589 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

809 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