SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Use case statement with other databases


Use case statement with other databases

Author
Message
frank 36119
frank 36119
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 34
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?
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63705 Visits: 17974
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 Modens 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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search