Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-03-03 : 08:07:33
|
| Liju Thomas writes "I am very new to SQL Server, infact to Database Programming also.So It would be very helpful, if anybody can help me for thisI have written one stored Procedure which returns a set of values from two tables. here is the Stored Procedure :-IF EXISTS (SELECT Name FROM SysObjects WHERE Name = 'SYNSelectFromSynSalary' AND TYPE = 'P')DROP PROCEDURE SYNSelectFromSynSalaryGOCREATE PROCEDURE SYNSelectFromSynSalary@EmpID int OUTPUT,@EmpRegionalCode char(10) OUTPUT,@EmpName varchar(25) OUTPUT,@EmpBand char(5) OUTPUT,@Designation varchar(25) OUTPUT,@NetSalary money OUTPUTWITH ENCRYPTIONASSELECT @EmpID = A.EmpID, @EmpRegionalCode = A.EmpRegionalCode, @EmpName = A.EmpName,@EmpBand = A.EmpBand, @Designation = A.Designation, @NetSalary = B.NetSalaryFROMSYNEmployee A JOIN SYNSalaryDetails BONA.EmpID = B.EmpIDANDA.EmpRegionalCode = B.EmpRegionalCodeORDER BYA.EmpRegionalCodeGOThis should retrieve all the Employee ID ,Regional Code, name etc from two tables.But after executing the above SP, Iam getting only the first row instead of 3 rows. Here is how i execute itDECLARE @EmpID int,@EmpRegionalCode char(10),@EmpName varchar(25),@EmpBand char(5),@Designation varchar(25),@NetSalary moneyEXEC SYNSelectFromSynSalary @EmpID OUTPUT,@EmpRegionalCode OUTPUT,@EmpName OUTPUT,@EmpBand OUTPUT,@Designation OUTPUT,@NetSalary OUTPUTIF @@ROWCOUNT = 0PRINT ('No Data Found')ELSEBEGINSELECT RTRIM(CAST(@EmpID AS CHAR(2))), RTRIM(@EmpRegionalCode), RTRIM(@EmpName), RTRIM(@EmpBand),RTRIM(@Designation), CONVERT(CHAR(10),@NetSalary)PRINT (CAST(@@ROWCOUNT AS CHAR(2)) + ' Records Found')ENDGOHere actually this query should return three rows, but i am getting only the first row. Is there any thing i need to do with the cursor for returning all the rows? If then, can anybody explain me, what is the use of cursor?" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-03 : 08:10:17
|
why are you returning column values via output paramteres????that will result in the last record in the resultset.varable can hold only one value at the time.do justSELECT A.EmpID, A.EmpRegionalCode, A.EmpName, A.EmpBand, A.Designation, B.NetSalaryFROMSYNEmployee A JOIN SYNSalaryDetails BONA.EmpID = B.EmpIDANDA.EmpRegionalCode = B.EmpRegionalCodeORDER BYA.EmpRegionalCodeand you should be ok.Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|
|
|