March 29, 2013 at 4:08 am
Hi,
I have a screen from which some columns values like VoucherNo, Denomination, Quantity etc. I have to matched those values from my database tables that those values exists or not. If they exists then I have to stored those values in a separate table and if not matched then I have to store in a separate table.
can you plz tell me how can I achieve this?
How can I matched the value?
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 29, 2013 at 4:12 am
I am implementing in this way. is it correct?
Please suggest
Declare @message1 nvarchar(100) = 'Invalid Voucher Type',
@message2 nvarchar(100) = 'Invalid Voucher Number',
@message3 nvarchar(100) = 'Invalid Denomination Number',
@message4 nvarchar(100) = 'Invalid TransactionID',
@message5 nvarchar(100) = 'Invalid Quantity'
Create table #temp
(
TransactionID varchar(10),
VoucherNo varchar(10),
ErrorMessage varchar(100)
)
IF NOT EXISTS (SELECT distinct a.VoucherTypeId from GV_Voucher a
inner join GV_VoucherType b ON a.VoucherTypeId = b.VoucherTypeID
WHERE a.TransactionID = 'TRN0000005'
)
BEGIN
INSERT INTO #temp
SELECT @TransactionID, @voucherNo, @message1
END
ELSE
BEGIN
INSERT INTO GV_ReceivedOffice
SELECT @voucherNo, GETDATE(),1
END
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 29, 2013 at 4:46 am
Try using a MERGE statement instead.
Inserting, Updating, and Deleting Data by Using MERGE
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 29, 2013 at 5:16 am
Koen Verbeeck (3/29/2013)
Try using a MERGE statement instead.
But I am doing only insertion not updation...Will it be good to use it only for isnertion?
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 29, 2013 at 5:28 am
kapil_kk (3/29/2013)
Koen Verbeeck (3/29/2013)
Try using a MERGE statement instead.But I am doing only insertion not updation...Will it be good to use it only for isnertion?
No, you're right. I overlooked the part where you have two different INSERTS.
Your logic makes sense.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply