webForumDet fria alternativet

Om nåt värde är tomt, ändå visa resten.

Databaser & SQL

5 svar · 477 visningar · startad av jwradhe

Medlem sedan juni 2002711 inlägg
Frågan#1

Hej! Jag håller på med en sql sökning, där ja ska ha ut massor av värden.
Ifall alla i ifyllda funkar det kanon, men om nåt värde är NULL tex, så skiter sig hela koden och allt blir tomt.

hur löser jag detta? Hittade inget direkt när jag sökte.

select 
PRHeaderTemplate.Title, 
PRHeaderTemplate.Description, 
PRHeaderTemplate.foreignid, 
PRHeaderTemplate.Origin, 
PRHeaderTemplate.Erranddescription, 
PRHeaderTemplate.Impact, 
PRHeaderTemplate.Solutions, 
PRHeaderTemplate.Downtime, 
PRHeaderTemplate.Duedate, 
PRHeaderTemplate.MinRegTime, 
CMProducts.ProductName, 
PRType.PRTypeName, 
PRSeverityType.Description, 
CMCountry.Country as CountryName, 
CMCompanies.CompName, 
Responsible.Name as ResponsibleName, 
Assigned.Name as AssignedToName, 
PRStatusType.Description, 
PRSourceType.SourceName, 
PRErrorTypes.ErrorName,
CMProductsVersions.Version, 
PRApps.AppName, 
CMProcess.ProcessName, 
PRInvoiceStatus.InvoiceStatusName, 
CMWorkType.WorkTypeName, 
reportedbyperson.Name 
from 
PRHeaderTemplate 
INNER JOIN PRType ON PRHeaderTemplate.PRTypeId = PRType.PRTypeID 
INNER JOIN PRSeverityType ON PRHeaderTemplate.SeverityId = PRSeverityType.SeverityId 
INNER JOIN CMCountry ON (SELECT CountryID from CMCompanies where compid = PRHeaderTemplate.invoicecompany) = CMCountry.CountryId 
INNER JOIN CMCompanies ON PRHeaderTemplate.invoicecompany = CMCompanies.CompId 
INNER JOIN CMCompanyPeople AS Responsible ON PRHeaderTemplate.ResponsiblePersonId = Responsible.PersonId 
INNER JOIN CMCompanyPeople AS Assigned ON PRHeaderTemplate.AssignedToPersonId = Assigned.PersonId 
INNER JOIN CMProducts ON PRHeaderTemplate.ProdId = CMProducts.Prodid 
INNER JOIN PRStatusType ON PRHeaderTemplate.StatusId = PRStatusType.StatusId 
INNER JOIN PRSourceType ON PRHeaderTemplate.SourceId = PRSourceType.SourceId 
INNER JOIN PRErrorTypes ON PRHeaderTemplate.ErrorTypeId = PRErrorTypes.ErrorTypeId 
INNER JOIN CMProductsVersions ON PRHeaderTemplate.ProductVersionId = CMProductsVersions.ProductVersionId  
INNER JOIN PRApps ON PRHeaderTemplate.AppId = PRApps.Appid 
INNER JOIN CMProcess ON PRHeaderTemplate.processid = CMProcess.ProcessId 
INNER JOIN PRInvoiceStatus ON PRHeaderTemplate.invoicestatusid = PRInvoiceStatus.InvoiceStatusId 
INNER JOIN CMWorkType ON PRHeaderTemplate.worktypeid = CMWorkType.WorkTypeId 
INNER JOIN CMCompanyPeople AS reportedbyperson ON PRHeaderTemplate.reportedby = reportedbyperson.PersonId 
where PRHeaderTemplate.Id = '16'
Medlem sedan maj 20012 237 inlägg
#2

Pröva med LEFT OUTER JOIN

Medlem sedan juni 2002711 inlägg
#3

Jag är inget proffs på SQL, har bara lärt mig inner join ännu, va gör den för skillnad?
eller måste ja googla mig fram till det ;)

Medlem sedan juni 2002711 inlägg
#4

jag hittade min förklaring på hur dom skilljer sig, tack för tipset!

http://iwtjanster.idg.se/webbstudio/pub/artikel.asp?id=76

Medlem sedan juni 2002711 inlägg
#5

En annan fråga som kanske inte helt har med detta att göra, är att jag tar ju where id = nåt id, idt skickas i länken från sidan innan, och just nu har jag ett värde hela tiden, men om jag vill ha sidan med detta script uppe från början, och inte har nåt värde, hur fasen ska jag göra då?

Medlem sedan juni 20008 205 inlägg
#6

I sidan som visar upp resultatet har du en koll, om ID är angivet, använd det, annars använd ett default-värde. Typ?

331 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
132 ms — deklarationer (db)
0 ms — hämta statistik (cache)
195 ms — hämta tråd, inlägg och bilagor (db)
134 ms — ändringar (db)