rocky_498 (9/20/2012)
Hi guys thank you for your reply, I created below CURSOR and its work fine,DECLARE @sidint
Declare InsertSID Cursor For
Select DISTINCT Sid from MDB
where ADate = dateadd(day,datediff(day,1,GETDATE()),0)
AND SID NOT IN (SELECT SID FROM MRequest )
OPEN InsertSID
FETCH NEXT FROM InsertSampleID
INTO @sid
WHILE @@FETCH_STATUS = 0
BEGIN
IF (@SID <> 0)
BEGIN
EXEC [INSERT_SP] @sid
END
Fetch Next from InsertSID
into @sid
END
close InsertSID
deallocate InsertSID
IS any one have better idea, Please share with us.
Thank You.
You absolutely do NOT need a cursor for this. It probably does your data ok but the performance is going to get worse and worse as the size of the tables increase. Depending on the complexity of the your INSERT_SP this could either be done as a single insert statement or the INSERT_SP could be modified to use a table parameter. As I said before, we need to have ddl (create table and proc scripts), some sample data (insert statements) and desired output based on your sample data. The first link in my signature will help you figure out where to find and how to post that information.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/