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 |
|
tatasmove
Starting Member
4 Posts |
Posted - 2008-07-14 : 13:54:04
|
| Hi SQL experts,Im new in creating a stored procedure. I need to create an income report using stored procedure, my main concern is I dont know how to scan a record using stored procedure, the reason of doing this is I want to validate the existence of the items rendered to customers, if the item is already exists it will not insert instead i will get the qty for rendered item and the amount rendered then, from that I can get the sum of the qty rendered and the amount. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-14 : 14:07:15
|
just use IF EXISTS(SELECT 1 FROM YourTable WHERE PKCol=@YourParam)BEGIN SELECT @Qty=QTY,@Amt=Amt FROM yOurTable WHERE PK =@ParamENDELSEBEGININSERT INTO YourTableSELECT values....END |
 |
|
|
tatasmove
Starting Member
4 Posts |
Posted - 2008-07-14 : 14:16:06
|
| Sample output:itemdesc QTY AMOUNTCARDEPINE 10MG/10ML AMPULE 5 500.00CARDEPINE 2MG/2ML AMPULE 10 1,000.00CARDIAC MONITOR 7 700.00 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-14 : 14:23:47
|
quote: Originally posted by tatasmove Sample output:itemdesc QTY AMOUNTCARDEPINE 10MG/10ML AMPULE 5 500.00CARDEPINE 2MG/2ML AMPULE 10 1,000.00CARDIAC MONITOR 7 700.00
CREATE PROC GetYourData@itemdesc varchar(100),... other params@Qty int=0 OUTPUT,@Amount decimal(10,2)=0.00 OUTPUTASIF EXISTS(SELECT 1 FROM YourTable WHERE itemdesc =@itemdesc)BEGIN SELECT @Qty=QTY,@Amount=AMOUNT FROM yOurTable WHERE itemdesc =@itemdescENDELSEBEGININSERT INTO YourTableSELECT @itemdesc,.. other valuesENDGO and you will invoke it likeDECLARE @rQty int, @rAmt decimal(10,2)EXEC GetYourData value1,...,@rQty,@rAmtSELECT @rQty,@rAmt will give back the values |
 |
|
|
|
|
|
|
|