January 6, 2009 at 11:35 am
pat (1/6/2009)
i am blank now what do i need to do and how?
Try this for starters IF (EXISTS (SELECT fname FROM testtable WHERE fname = @Testname))
BEGIN
RAISERROR ('UPDATE',0,1) WITH NOWAIT
UPDATE testtable
SET TEMP = @tbg,CAST = @csg,volume = @MCF
WHERE testDate = @pm AND DAY= (@currentRow-@dataStartRow + 1)AND fname = @testname
END
ELSE
BEGIN
RAISERROR ('INSERT',0,1) WITH NOWAIT
INSERT INTO testtable([Filename],fname,testdate,DOM,TEMP,CAST,volume)
VALUES
(@srcFilename,@testname,@PM,(@currentRow-@dataStartRow + 1),@test1,@test2,@test3)
END
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 11:42 am
here is the thing when i did that the you u suggest.
I only does one insert and rest of them update. and file has 29 worksheet so i get only 29 records.
which is the first record only!!
January 6, 2009 at 11:51 am
pat (1/6/2009)
here is the thing when i did that the you u suggest.I only does one insert and rest of them update. and file has 29 worksheet so i get only 29 records.
which is the first record only!!
So...referring back to your original post, it looks like the part in bold is working (possibly), and something else isn't.
How many updates and inserts do you get for each worksheet? Count "UPDATE" and "INSERT" written by RAISERROR.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 12:00 pm
Hi,
i did that already and that's why i said that it only does one insert per worksheet(total count of worksheets are 29) and it updates the same reocords.
thanks
Pat
January 6, 2009 at 12:01 pm
pat (1/6/2009)
Hi,i did that already and that's why i said that it only does one insert per worksheet(total count of worksheets are 29) and it updates the same reocords.
thanks
Pat
So it does one INSERT and one UPDATE per worksheet?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 12:11 pm
no i does on insert but rest of them update like if worksheet has data till 24 rows it will run update till 24 but insert is one only!!
January 6, 2009 at 12:20 pm
pat (1/6/2009)
no i does on insert but rest of them update like if worksheet has data till 24 rows it will run update till 24 but insert is one only!!
The PRINT statement print 'Testname = ' + @Testname +
What is printed for @Testname for each row?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 12:31 pm
hey,
it also prints the name as well.
this is so wierd now.. if i put the print message on insert it does all insert but not update and it duplicates the recodrs 🙂
January 6, 2009 at 12:46 pm
Yes, it does. Is it always the same?
IF (EXISTS (SELECT fname FROM testtable WHERE fname = @Testname))
BEGIN
UPDATE testtable
SET TEMP = @tbg,CAST = @csg,volume = @MCF
WHERE testDate = @pm AND DAY= (@currentRow-@dataStartRow + 1)AND fname = @testname
END
ELSE
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 12:50 pm
yes
January 6, 2009 at 12:54 pm
pat (1/6/2009)
yes
Top work Pat, you've cracked it.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 12:56 pm
what?
January 6, 2009 at 1:09 pm
pat (1/6/2009)
what?
@Testname is assigned only outside the WHILE loop (WHILE @currentRow <= @dataEndRow) so remains static for each iteration.
This conditional ...IF (EXISTS (SELECT fname FROM testtable WHERE fname = @Testname))
... says: IF there's already a row where fname = @Testname then update it, otherwise insert it. Since @Testname is the same for all rows, only the first will be inserted - the rest will update.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 6, 2009 at 1:13 pm
then how will i write the insert and update please guide me!!
thanks
January 6, 2009 at 1:36 pm
pat (1/6/2009)
then how will i write the insert and update please guide me!!thanks
Sure! Remember that PRINT statement? Post what gets printed, say the first 10 lines for one worksheet.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 15 posts - 16 through 30 (of 34 total)
You must be logged in to reply to this topic. Login to reply