473,434 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

store Procedure

Hi,
how can i use 2 Query in store Procedure?
I have user table that have username, userId (primary key) field and have userinfo table that have userId ,userinfo(primary key),firstName field

I want to do this:

1.getting userId from user table : (select userId from user where username=@username )
2.adding userId into userinfo table:insert into userinfo ( userId,firstName) values(?????,@firstName)

I don't know,how can i getting value from one table and using it to another table.

Please Help Me.

Thanks.
May 16 '10 #1
1 1430
Jim Doherty
897 Expert 512MB
@marjani
I am not convinced at all by your logic in retrieving a userid from a table based on some users name and inserting the userid into a second table in the manner you prescribe. Peoples names are not unique (many Jims and Johns etc etc) but I suspect you are learning so you will realise soon enough I suspect.

Anyway, below is a very simple procedure that first SELECTS records existing in the user table (tbluser) matching the value of the username passed in as a parameter to the stored procedure.

Only if the row count of the recordset is equal to one does it insert the values into the second table

The logic of this procedural flow is deeply 'flawed' of course but you can work it out for yourself as I suspect you are merely learning 'how' to grab a value from one table and throw it into another

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.usp_insertUserInfo
  2. @username varchar(100) AS
  3.  
  4. DECLARE @mycount int
  5.  
  6. SELECT @mycount= (userid)  FROM tblusers WHERE username=@username
  7. IF @@rowcount=1 
  8. INSERT tbluserinfo (userid,firstname)
  9. SELECT userid,username FROM tblusers WHERE username=@username
  10. GO
May 16 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jin | last post by:
Hello: I run one process that calls the following the store procedure and works fine. create PROCEDURE sp_GetHostSequenceNum AS BEGIN SELECT int_parameter_dbf + 1
1
by: Hugo Lefevre | last post by:
Dear, I have a problem : I have a database which contains my data of hardware. The Id is a varchar and I want at my filling form that my user know which is the last one. So I made a store...
3
by: serge calderara | last post by:
Dear all, One simple question relative to store procedure withinh ASP code on a web page. Let say that I am calling a store procedure to execute from a server button click on my web page. That...
1
by: TARUN | last post by:
Hello All I get stuck in one problem , Please help me and excuse me on the poor Knowledge in SQL Server Store procedure Q1...I want to return a string type value from store procedure , Is it...
8
by: gacuna | last post by:
i want to insert into a temporal table the result of a store procedure. on sql server the sentence would look like this (already working) INSERT INTO #SHIPINFO exec TESTDTA.S59RSH05 @SCBILLTO,...
6
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
0
by: rxding | last post by:
Hello, Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while investigating some sample code of Java store procedure, ...
0
by: zhenyuandeng | last post by:
Hi, When i call the procedure sp_jysczld_new from the Query Analyzer, it runs slowly. But when i extract the sql scripts from the procedure sp_jysczld_new, it runs quickly. Why? I don't...
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
2
by: kuchel | last post by:
Hi I am trying to run 4 - 5 store procedure in a strict order. I have created a SSIS package whereby I trying to execute store procedure in a orderly fashion. I have created constraints between...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.