Solved

Using Functions In Views I.E.  Trim or iif

Posted on 2007-12-06
2
778 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 142

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server computed columns 11 31
insert wont work in SQL 14 22
CPU high usage when update statistics 2 30
Flattening heirachies 3 30
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

777 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