Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2010, 05:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default REPLACE first character when...?

Having trouble writing a complex select. This is what I have at this point:

RIGHTOUTERJOIN
Common.dbo.T_pin ON OfficeInfo.dbo.vwTestS8DDS.OfficeCode = Common.dbo.T_pin.FOC

In brief, I want to check the value Common.T_Pin.FOC, and if the first character='R' I want to change it to 'F'. I then want to use that altered value in the join. It doesn't seem to like a reference to a CASE function in the JOIN. Nor can I create a variable, because the result of this is a view.

Clues?

 
Old January 26th, 2010, 09:34 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

So why not create a VIEW of Common.dob.T_pin that has the FOC already fixed up as you want it??

That is:
Code:
CREATE VIEW whatever 
AS
SELECT a,b,c,
       (CASE WHEN LEFT(FOC,1) = 'R'
                  THEN 'F' + SUBSTRING(FOC,2,LEN(FOC)-1)
                  ELSE FOC
        END) AS FOC
FROM Common.dbo.T_pin
And then use that in your JOIN??
 
Old January 27th, 2010, 04:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Thanks for your response, Old Pedant! I'd considered the idea before posting my question, but the view I'm creating is being consumed by yet another view, and that view is already occasionally timing out with simple selects in the Management Studio. I was concerned another level of nested views could degrade performance significantly. But as this appears to be the only solution, I will give it a shot.

Thanks again!

PS - If anybody from P2P is following this, email notification of responses to this thread appears to have failed.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace character gregalb SQL Server 2000 6 July 12th, 2007 01:14 AM
SQL REPLACE after a character. Stuart Stalker SQL Server 2000 6 April 11th, 2006 02:13 PM
Character replace function? echovue Access 2 December 21st, 2004 01:53 PM
Replace Character " fosca XSLT 1 November 11th, 2004 04:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.