SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


No results...


No results...

Author
Message
pk2dpvp
pk2dpvp
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 101
-- SSIS IMPORT


GO

-- Wijziging aanpassen van dummy table naar artikelen table.
UPDATE a
SET [omschrijving] = SP.[omschrijving]
,[verkoopprijs] = SP.[verkoopprijs]
,[gewijzigd] = getDate()
FROM [artikelen] a
LEFT OUTER JOIN [Hofstede].[dbo].[sparepartsupdate] SP
ON a.[PartNrFabrikant] = SP.[PartNrFabrikant]
WHERE (A.omschrijving != SP.[omschrijving]) OR (A.[verkoopprijs] != SP.[verkoopprijs]);

GO

-- Controleren wat er verwijdert is door te kijken wat er WEL in de artikel table zit maar niet meer in de dummy table.
UPDATE a
set [Verwijderd] = getDate()
from [artikelen] a
LEFT OUTER JOIN [Hofstede].[dbo].[sparepartsupdate] SP
ON a.[PartNrFabrikant] NOT IN (SP.[PartNrFabrikant])

GO

-- De toegevoegde artikelen toevoegen aan de artikel table.
UPDATE a
SET [omschrijving] = SP.[omschrijving]
,[verkoopprijs] = SP.[verkoopprijs]
,[toegevoegd] = getDate()
FROM [artikelen] a
LEFT OUTER JOIN [Hofstede].[dbo].[sparepartsupdate] SP
on sp.[PartNrFabrikant] NOT IN (a.[PartNrFabrikant])

GO

-- De dummy table na gebruik weer verwijderen.
-- UITGESCHAKELD VOOR TEST -- DELETE sparepartsupdate



the second and third query are supposed to check what changed and the 3rd one checks what has been deleted...

I deleted about 250 rows in Sparepartsupdate but it doesn't recognise them after executing this query which takes about half an hour
I have also changed a few but either these will not be recognised.

what am I doing wrong this time? ;p
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27119 Visits: 13268
Second query:

UPDATE a
set [Verwijderd] = getDate()
from [artikelen] a
WHERE NOT EXISTS (SELECT 1 FROM [Hofstede].[dbo].[sparepartsupdate] SP WHERE a.[PartNrFabrikant] = SP.[PartNrFabrikant]);

The third query, shouldn't that be an INSERT statement?

ps: dt-fout in commentaar van tweede query ;-)


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
pk2dpvp
pk2dpvp
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 101
yupp...
After an hour of trying everything I could possibly think of I came to the conclusion that I am unable to create anything with insert into:p
pk2dpvp
pk2dpvp
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 101
-- De toegevoegde artikelen toevoegen aan de artikel table.
INSERT INTO artikelen AR
SET [toegevoegd] = getDate()
LEFT JOIN [Hofstede].[dbo].[sparepartsupdate]
WHERE [artikelen] not in [sparepartsupdate]

I can't get any further so basically I'm pretty stuck on my insert query :p
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16034 Visits: 19524
The first query may not be doing what you expect. If you reference a column from a left-joined table in the WHERE clause, the left join is converted to an INNER join - except for the special case WHERE [column] IS NULL.

To preserve the outer join, change your query so that the filter is applied to the join, like this:
UPDATE a
SET [omschrijving] = SP.[omschrijving]
,[verkoopprijs] = SP.[verkoopprijs]
,[gewijzigd] = getDate()
FROM [artikelen] a
LEFT OUTER JOIN [Hofstede].[dbo].[sparepartsupdate] SP
ON a.[PartNrFabrikant] = SP.[PartNrFabrikant]
AND ((A.omschrijving <> SP.[omschrijving]) OR (A.[verkoopprijs] <> SP.[verkoopprijs]));



Note that for rows in artikelen which don't have a match in SP, [omschrijving] and [verkoopprijs] will be set to NULL - is this what you are expecting?

Is PartNrFabrikant a primary key in either table?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
pk2dpvp
pk2dpvp
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 101
If I change WHERE to AND it gives me this..:

(408014 row(s) affected)

which with where is:

(2054 row(s) affected)

---------------------------------------------

Isn't this because it doesn't know what to do with AND so it affects every value found by "ON"? (Which is everything that did NOT change)?
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16034 Visits: 19524
pk2dpvp (6/6/2014)
If I change WHERE to AND it gives me this..:

(408014 row(s) affected)

which with where is:

(2054 row(s) affected)

---------------------------------------------

Isn't this because it doesn't know what to do with AND so it affects every value found by "ON"? (Which is everything that did NOT change)?


It's because the outer join is converted to an inner join. You need to decide what you want to do here. My guess is you want an inner join, where non-matching rows would be unaffected by the update. If this is the case, write the join as an inner join and it doesn't matter where you put the filter.
Alternatively, if you want all rows to be affected by the update, with matching rows taking values from the second table and nonmatching rows taking NULL values, then write it as a left join with the filter in the join.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
pk2dpvp
pk2dpvp
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 101
aye, got it all working fine now, tested and well Smile

Though, I still didn't get the insert script working :p
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27119 Visits: 13268
pk2dpvp (6/6/2014)
aye, got it all working fine now, tested and well Smile

Though, I still didn't get the insert script working :p


Take a look at the following MSDN page:
INSERT (Transact-SQL)

SET is not part of the INSERT syntax.
Also, you use NOT IN usually in the following way:

WHERE columnA NOT IN (SELECT columnB FROM anotherTable) -- you should have a list of values here


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
pk2dpvp
pk2dpvp
SSC Rookie
SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)SSC Rookie (43 reputation)

Group: General Forum Members
Points: 43 Visits: 101
haha I tried to understand it but it completely fkedup my brain :p
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search