?
Solved

defining a variable in stored procedure in SQL Server and MySQL

Posted on 2012-04-06
10
Medium Priority
?
637 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

764 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