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.
Author |
Topic |
nechtmarrie
Starting Member
24 Posts |
Posted - 2013-09-04 : 06:43:45
|
Hi,I currently have a querry that gathers data for a report to be printed out.Basicly what it dous is it checks wether the truck number assinged to a shipment is a "Bakwagen" and if the type of chauffeur/driver is a dag/day type.SELECT Planlijst.Plan_ID, Planlijst.Datum, Planlijst.Nummer, Planlijst.Naam, Planlijst.Vertrek, Planlijst.Vertrek_Tikklok, Planlijst.Rit_1, Planlijst.Rit_2, Planlijst.Rit_3, Planlijst.TrailerNo1, Planlijst.TrailerNo2, Planlijst.TrailerNo3, Planlijst.smsstatus, Planlijst.IncidentieelFROM Planlijst LEFT OUTER JOIN Vrachtwagens ON Planlijst.Nummer = Vrachtwagens.Nummer INNER JOIN Chauffeurs ON Planlijst.Naam = Chauffeurs.NaamWHERE (Planlijst.Datum = @Datum) AND (Chauffeurs.Type = 'Dag') AND (Vrachtwagens.Type = 'Bakwagen')Now i want to also include shipments where the incidential field is set to 1, instead of the chauffeur beying a day type. So i adjusted my querry to the following:SELECT Planlijst.Plan_ID, Planlijst.Datum, Planlijst.Nummer, Planlijst.Naam, Planlijst.Vertrek, Planlijst.Vertrek_Tikklok, Planlijst.Rit_1, Planlijst.Rit_2, Planlijst.Rit_3, Planlijst.TrailerNo1, Planlijst.TrailerNo2, Planlijst.TrailerNo3, Planlijst.smsstatus, Planlijst.IncidentieelFROM Planlijst LEFT OUTER JOIN Vrachtwagens ON Planlijst.Nummer = Vrachtwagens.Nummer INNER JOIN Chauffeurs ON Planlijst.Naam = Chauffeurs.NaamWHERE (Planlijst.Datum = @Datum) AND (Planlijst.Incidentieel = 1 OR Chauffeurs.Type = 'Dag') AND (Vrachtwagens.Type = 'Bakwagen')This however dous not work, it just shows all the results like before but not any shipments that are marked incidential.Anyone knows why this is?grts,Necht |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-04 : 06:51:45
|
--try thisWHERE (Planlijst.Datum = @Datum) AND (Planlijst.Incidentieel = 1 OR Chauffeurs.Type = 'Dag') AND (Vrachtwagens.Type = 'Bakwagen')--Chandu |
|
|
nechtmarrie
Starting Member
24 Posts |
Posted - 2013-09-04 : 06:59:56
|
If i would use that all the orders where incidential = 0 would not be displayed anymore. |
|
|
nechtmarrie
Starting Member
24 Posts |
Posted - 2013-09-04 : 07:37:58
|
I tried running the querry with that adjustment just now and it returns no results at all |
|
|
nechtmarrie
Starting Member
24 Posts |
Posted - 2013-09-04 : 09:09:56
|
I solved it using an UNION, combining 2 querrys |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-04 : 09:13:50
|
ok... try this tooSELECT Planlijst.Plan_ID, Planlijst.Datum, Planlijst.Nummer, Planlijst.Naam, Planlijst.Vertrek, Planlijst.Vertrek_Tikklok, Planlijst.Rit_1, Planlijst.Rit_2, Planlijst.Rit_3, Planlijst.TrailerNo1, Planlijst.TrailerNo2, Planlijst.TrailerNo3, Planlijst.smsstatus, Planlijst.IncidentieelFROM Planlijst LEFT OUTER JOINVrachtwagens ON Planlijst.Nummer = Vrachtwagens.Nummer INNER JOINChauffeurs ON Planlijst.Naam = Chauffeurs.NaamWHERE (Planlijst.Datum = @Datum) AND (Planlijst.Incidentieel = 1 AND Chauffeurs.Type = 'Dag') AND (Vrachtwagens.Type = 'Bakwagen')--Chandu |
|
|
|
|
|
|
|