Solved

Using Functions In Views I.E.  Trim or iif

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
execute a MS SQL script as a schedule SQL job 72 101
PL/SQL query 14 51
C# SQL BULK INSERT CLASS 5 36
sql server query? 6 28
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now