Solved

Using Functions In Views I.E.  Trim or iif

Posted on 2007-12-06
2
781 Views
Last Modified: 2008-02-01
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
Comment
Question by:ssteeves
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 20419593
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
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20419600
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Encrypting SQL Server 2014 or SQL Server 2016 4 30
job schedule 8 19
SQL Recursion 6 19
Casting is giving error in sql server 3 11
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question