Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Selection with flag Problem

Author  Topic 

zero1de
Posting Yak Master

105 Posts

Posted - 2012-07-09 : 05:15:45
Hi,
the switch flag Archiviert=0 also get Row's with status=1. I would like to have only records, the only have Archived=0 status. What is wrong here ?

Field Archive is int.

My SP query to do this here.

CREATE PROCEDURE [dbo].[sp_update_Immo_Meta]
WITH EXEC AS CALLER
AS
UPDATE I
SET Nachname = P.NAME1,
Vorname = P.NAME2,
ENGAGEMENTNR = P.ENGAGEMENT,
FORDERGNR = P.FORDERGNR,
PARTNERID = P.PARTNERID,
GLAEUBIGERNR = P.GLAEUBIGERNR,
GEBURTSDATUM = P.GEBURTSDATUM,
SPARTE = P.BEZSPARTE,
ZUSTSACHB = P.AKTENEIGNER,
HAUPTSCHULDNER = P.HAUPTSCHULDNER,
Fordnr = P.Fordnr,
Dokdatum = coalesce(Dokdatum, getdate()),
ARCHIVIERT = 1
FROM immo I
INNER JOIN TBL_IMMO_PARTNER P
ON i.Fordnr = P.Fordnr or i.partnerid = p.partnerid
WHERE ISNULL(i.archiviert,0)=0
AND i.stapelnummer = 'Tiff_Printer' or i.stapelnummer='Fax/E-Mail'

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2012-07-09 : 07:25:46
Hi

Are all of your non 1 values actually null, they may be empty string. So you could put:


WHERE ISNULL(NULLIF(i.archiviert, ''),0)=0


To check just:


select i.archiviert
from table
where i.archiviert = ''
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-09 : 09:41:47
One issue i see here is you have an open OR condition which will cause all other conditions to bypass in WHERE. i think you need this



....
WHERE ISNULL(i.archiviert,0)=0
AND (i.stapelnummer = 'Tiff_Printer' or i.stapelnummer='Fax/E-Mail')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -