Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Assign result set to scalar?

Posted on 2013-06-05
2
Medium Priority
?
298 Views
Last Modified: 2013-06-05
I have a standard procedure where  MyNumber is passed in as a parameter.
Using it, I want to get the value of tblMyTable.MyId and assign it to @MyId
How do I do this?
 
DECLARE @Myid as int
select [Myid] from [MyDB].[dbo].[tblMyTable]
where [MyNumber] = @MyNumber
-- @MyId = [Myid] ???
-- use @Myid at this point

Open in new window

0
Comment
Question by:allelopath
[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
2 Comments
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 2000 total points
ID: 39222125
DECLARE @Myid as int
select  @Myid = [Myid] from [MyDB].[dbo].[tblMyTable]
where [MyNumber] = @MyNumber
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39222136
You have two variables used in your query, @Myid and @MyNumber. If you want to select from the table based on the passed-in variable only, then you don't need both.

DECLARE @MyNumber INT
SET @MyNumber = 12345

SELECT MyID, col1, col2, ..... FROM MyTable
WHERE MyID = @MyNumber

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

721 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