Solved

defining a variable in stored procedure in SQL Server and MySQL

Posted on 2012-04-06
10
626 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 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

691 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