SQLTeam.com | Weblogs | Forums

SQL error help

tsql

#1

Why is this sql statement returning no results. I am stumped.

  UPDATE  Snapshot

  SET gelewer_h = i.lewering, 
  klaar = i.klaar 
 FROM (
    SELECT plaasno,blokno,lewering,klaar 
    FROM LeweringVsSkatting) i
WHERE 
i.plaasno = snapshot.plaasno
and
i.blokno = snapshot.blokno

Anyone can spot what I am missing ?


#2

I don't think it will be any different, but I would have written the query like this:

UPDATE	U
SET	gelewer_h = i.lewering, 
	klaar = i.klaar 
FROM	Snapshot AS U
	JOIN LeweringVsSkatting AS i
		 ON i.plaasno = U.plaasno
		and i.blokno = U.blokno

#3

Thanks Kisten, still 0 rows affected.


#4

Presumably this gives 0 rows then:

SELECT COUNT(*)
FROM	Snapshot AS U
	JOIN LeweringVsSkatting AS i
		 ON i.plaasno = U.plaasno
		and i.blokno = U.blokno

if so you need to find the rows that you were expecting to be updated and then figure out why they were not included in that query


#5

Oops my mistake. Snapshot had no records.


#6

Good to have a reason :slight_smile: