• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

If Statement in SQL Query (Blank Name)

I have this SQL code, in it I have a linked static Table that links new names based on CustomerName.. Now if theres no name to link it just shows up blank. I was wonder if I can add an if stamtment that if there no linked name instead of blank can it be Named to "Other"?  1
SELECT     IMSPCGroupSPC.SPCGroup, SNSalesRep.Name, AllSales.Sales, AllSales.SDYEAR, AllSales.Cost, AllSales.CustomerName, 
                      ICI_ForecastWorkSheet_Forecast.[Sales F], ICI_ForecastWorkSheet_Forecast.[Cost F], ICI_ForecastWorkSheet_Forecast.[GP F], 
                      AllSales.CustomerNum, AllSales.Territory, ['Linked Names$'].[Forecast Name]
FROM         IMSPCGroupSPC RIGHT OUTER JOIN
                      AllSales ON IMSPCGroupSPC.SPC = AllSales.SPC LEFT OUTER JOIN
                      ['Linked Names$'] ON AllSales.CustomerName = ['Linked Names$'].CustomerName LEFT OUTER JOIN
                      SNSalesRep ON AllSales.Territory = SNSalesRep.SalesRep FULL OUTER JOIN
                      ICI_ForecastWorkSheet_Forecast ON AllSales.CustomerNum = ICI_ForecastWorkSheet_Forecast.Customer AND 
                      IMSPCGroupSPC.SPCGroup = ICI_ForecastWorkSheet_Forecast.[SPC Group] AND AllSales.Territory = ICI_ForecastWorkSheet_Forecast.Rep
WHERE     (AllSales.SDYEAR = 2010) OR
                      (AllSales.SDYEAR = 2011)
ORDER BY AllSales.SDYEAR, ['Linked Names$'].[Forecast Name] DESC

Open in new window

0
gotti777
Asked:
gotti777
1 Solution
 
tigin44Commented:
SELECT     IMSPCGroupSPC.SPCGroup, SNSalesRep.Name, AllSales.Sales, AllSales.SDYEAR, AllSales.Cost, AllSales.CustomerName,
                      ICI_ForecastWorkSheet_Forecast.[Sales F], ICI_ForecastWorkSheet_Forecast.[Cost F], ICI_ForecastWorkSheet_Forecast.[GP F],
                      AllSales.CustomerNum, AllSales.Territory, ISNULL(['Linked Names$'].[Forecast Name], 'Other')
FROM         IMSPCGroupSPC RIGHT OUTER JOIN
                      AllSales ON IMSPCGroupSPC.SPC = AllSales.SPC LEFT OUTER JOIN
                      ['Linked Names$'] ON AllSales.CustomerName = ['Linked Names$'].CustomerName LEFT OUTER JOIN
                      SNSalesRep ON AllSales.Territory = SNSalesRep.SalesRep FULL OUTER JOIN
                      ICI_ForecastWorkSheet_Forecast ON AllSales.CustomerNum = ICI_ForecastWorkSheet_Forecast.Customer AND
                      IMSPCGroupSPC.SPCGroup = ICI_ForecastWorkSheet_Forecast.[SPC Group] AND AllSales.Territory = ICI_ForecastWorkSheet_Forecast.Rep
WHERE     (AllSales.SDYEAR = 2010) OR
                      (AllSales.SDYEAR = 2011)
ORDER BY AllSales.SDYEAR, ['Linked Names$'].[Forecast Name] DESC
0
 
gotti777Author Commented:
Perfect Thanks you !
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now