Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

defining a variable in stored procedure in SQL Server and MySQL

Posted on 2012-04-06
10
Medium Priority
?
647 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
10 Comments
 
LVL 10

Accepted Solution

by:
plummet earned 1000 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 18

Assisted Solution

by:lludden
lludden earned 1000 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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

618 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