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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Need Some help with the 'Select' Statement

Author  Topic 

shyamprasad76
Starting Member

38 Posts

Posted - 2001-11-21 : 11:37:35
Hi,

I am trying to load a dimension table in an OLAP database for which i am writing a SQL Statement on one of my Datawarehouse table.

The question is on the framing of the select
statement.Basically the SQL 'SELECT' statement is trying to accomplish the folowing:

- First it should check whether a particular column in the target table has a pre disgnated value(like last 3 characters are '000'), if it has - it takes that column as it's first field Or Else it has to take another column from the table.

This logic continues for other fields in the table as well.

Somebody (my predecessor) said he could accomplish fairly easily with Microsft ACCESS, but i could not do this with Microsft SQL SERVER 2000 or 7.0.

The Query in MS ACCESS Looks like this:

SELECT IIf(Mid([CustID],6,8)="000",Trim([CustomerName])
& " (" & [CustID] & ")",Trim([BillingDepartmentName]) & "
(" & [CustId] & ")") AS N,
IIf([N]=Trim([CustomerName]) & " (" & [CustID] & ")",IIf
([CMID],[CMID],"Total"),Trim([CustomerName]) & " (" & Left
([CustID],5) & ")") AS C1,
IIf([C1]="Total","",IIf([C1]=Trim([CustomerName]) & " (" &
Left([CustID],5) & ")",IIf([CMID],[CMID],"Total"))) AS C2,
IIf([C2]=[CMID],"Total","") AS C3,
dbo_Customer.BranchName,
dbo_Customer.ActivationDate,
dbo_Customer.ARBalance,
dbo_Customer.DSO,
dbo_Customer.CustID
FROM dbo_Customer;

CAN ANYONE write this in SQL Server. I tried CASE but could not. Is there any equivivalent of an IFF statement - ACCESS, in MSFT SQL Server.

Thanks,

Shyam.
   

- Advertisement -