Hello and welcome to CertForums.co.uk, here we host free active certification forums with links to the best free resources for Microsoft's MCSA MCSE MCDBA Cisco's CCNA CCDA and CCNP, and CompTIA's A+ Network+ i-NET+ and Security+ certifications in the UK. If you wish to post or use other advanced features you will need to register first. Registration is absolutely free and takes only a few minutes to complete so sign up today!

If you have any problems with the registration process or your account login, please contact support

Go Back   CertForums > Certification Forums > Microsoft Certification Forums > SQL Exams
Home Forums Register Search Today's Posts Mark Forums Read

Custom Expression in SQL

Post New ThreadReply
 
Thread Tools Display Modes
  #1  
Old 11-Oct-2007, 01:12 PM
Fergal1982's Avatar
Fergal1982 Fergal1982 is offline CertForums News Posting Member
Linux Àihǎozhě: bù zàihū!
Posts: 2,861
Points: 4243 Fergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 points
Power: 78
None
Join Date: 04 May 2004
Location: Aberdeen, UK
Age: 25
Certifications: ITIL Foundation
WIP: 70-536,70-294,(A+), Procastination+
Custom Expression in SQL

Does anyone know how to set up a custom expression using T-SQL?

I basically have a query that returns a bit column. I need to provide custom output from the query so that, if the value is 1 it returns a set string.

Does that make any sense?


"Im Nerdy in the extreme and whiter than sour cream"


ObsidianPhoenix - my development blog



 
Reply With Quote
  #2  
Old 11-Oct-2007, 02:37 PM
Ossian Ossian is offline
New Member
Posts: 38
Points: 0 Ossian has no points
Power: 2
None
Join Date: 14 Sep 2007
Location: Bonnie Scotland
Certifications: MCT, MCSE/A, MCDBA, MCDST, MCITP, Sec+
WIP: Not sure....
Define a custom function e.g. ProcessBit taking the bit value as a parameter

e.g.
CREATE FUNCTION dbo.ProcessBit( @booVal bit)
RETURNS varchar(20)
AS
BEGIN
IF @booVal --should default to true
RETURN 'True String'
ELSE
RETURN 'False String'

END


then

SELECT ProcessBit(fieldname) AS "Result" FROM tablename

Note this is not checked code, just a rough example!


Tom Jones
MCT, MCSE (2000:Security, 2003), MCSA:Messaging & Security, MCDBA, MCDST, MCITP, MCTS, MCP, Sec+
PhD, MSc, FIAP, MIITT
ICT Trainer / Consultant
Ossian Ltd
Scotland
 
Reply With Quote
  #3  
Old 11-Oct-2007, 02:39 PM
Fergal1982's Avatar
Fergal1982 Fergal1982 is offline CertForums News Posting Member
Linux Àihǎozhě: bù zàihū!
Posts: 2,861
Points: 4243 Fergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 pointsFergal1982 has over 4000 points
Power: 78
None
Join Date: 04 May 2004
Location: Aberdeen, UK
Age: 25
Certifications: ITIL Foundation
WIP: 70-536,70-294,(A+), Procastination+
Yeah I thought of doing that. Didnt want to use stored procedures if i could avoid it.

Dont worry too much though, I realised I was being stupid and doing the wrong query, so its a moot point.


"Im Nerdy in the extreme and whiter than sour cream"


ObsidianPhoenix - my development blog



 
Reply With Quote
Post New ThreadReply Spread this thread: Submit this thread to digg Submit this thread to del.icio.us


Go Back   CertForums > Certification Forums > Microsoft Certification Forums > SQL Exams


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL VS ORACLE the_beast SQL Exams 11 05-Feb-2008 03:41 PM
Any SQL Gurus? nXPLOSi SQL Exams 3 05-Oct-2007 04:13 PM
SQL Server 2005 Compact Edition tuvanit Software 0 15-Dec-2006 12:20 PM
CertForums 70-228 & 70-229 Forum FAQ Page Phil SQL Exams 0 19-Nov-2003 06:24 AM


All times are GMT. The time now is 09:33 PM.

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
CertForums.co.uk (C) copyright 2003-2007 All Rights Reserved. Content published on CertForums.co.uk requires permission for reprint.
Hosted by Lunarpages