Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Use case statement with other databases Expand / Collapse
Author
Message
Posted Friday, November 8, 2013 8:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 1:50 PM
Points: 1, Visits: 11
I am looking to incorporate replace statements in a case statement. I have a view which produces the data that need and I have a query that updates fields in one table from another table. I would like to use this query in a CASE statement.

This is how I am updating wtih the query:
update Master_Hierarchy
set OrgID = REPLACE(a.OrgID,b.[OLD CC ID],b.[NEW CC ID]),
AccountID = REPLACE(a.AccountID,b.[closed SBU ID],b.[NEW SBU ID]),
Alias = REPLACE(a.Alias,b.[closed SBU ID],b.[NEW SBU ID])
from Master_Hierarchy a inner join CloseCons b
on a.OrgID = b.[OLD CC ID]

I am thinking something along the lines of:

SELECT CASE
WHEN a.client_sbu = b.[closed SBU ID] Then b.[NEW SBU ID]
else
END as 'client_sbu'

However I want to do this in a view. Is this even possible?
Post #1512715
Posted Friday, November 8, 2013 9:26 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:54 PM
Points: 13,471, Visits: 12,329
frank 36119 (11/8/2013)
I am looking to incorporate replace statements in a case statement. I have a view which produces the data that need and I have a query that updates fields in one table from another table. I would like to use this query in a CASE statement.

This is how I am updating wtih the query:
update Master_Hierarchy
set OrgID = REPLACE(a.OrgID,b.[OLD CC ID],b.[NEW CC ID]),
AccountID = REPLACE(a.AccountID,b.[closed SBU ID],b.[NEW SBU ID]),
Alias = REPLACE(a.Alias,b.[closed SBU ID],b.[NEW SBU ID])
from Master_Hierarchy a inner join CloseCons b
on a.OrgID = b.[OLD CC ID]

I am thinking something along the lines of:

SELECT CASE
WHEN a.client_sbu = b.[closed SBU ID] Then b.[NEW SBU ID]
else
END as 'client_sbu'

However I want to do this in a view. Is this even possible?


Sure you can use a case expression in a view.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1512725
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse