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

Using Functions In Views I.E. Trim or iif

Using SQL Server 2000, I want to add a new View, such as this:

SELECT Trim([Name]) From [tblData]

or

Select iif([Age] < 30, 'Young', 'Old') From tblAges

In the first case, it tells me unrecognized function, and in the second case, it tells me it doesn't recognize it doesn't recognize the Equal sign.  

Any suggestions?
0
ssteeves
Asked:
ssteeves
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sql server does not have trim, but does have ltrim and rtrim
SELECT rtrim(lTrim([Name])) From [tblData]

iif will be translated into a case statement:

Select CASE WHEN [Age] < 30 THEN 'Young' ELSE 'Old' END From tblAges
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
IFF  is not a recognised function in sql server

Select case when [Age] < 30 then  'Young' else  'Old'  end  as SomeColumn  From tblAges
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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