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


If branch then 'HDQ CityName, State


If branch then 'HDQ CityName, State

Author
Message
NewBornDBA2017
NewBornDBA2017
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3679 Visits: 913
I have a table and a user requested a data and he wants me to format it in a way he wants it. I can't find a way to do it but before I tell him that, I am still working on figuring this out.
The attached file contains the data, however; instead of showing 'Branch' in a Headquarter column, he wants the value ('HDQ, and the city of HQ + State). Is it even possible? I can't think of anything.
Attachments
Headquarter.PNG (9 views, 58.00 KB)
drew.allen
drew.allen
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62346 Visits: 16632
NewBornDBA2017 - Wednesday, September 12, 2018 3:02 PM
I have a table and a user requested a data and he wants me to format it in a way he wants it. I can't find a way to do it but before I tell him that, I am still working on figuring this out.
The attached file contains the data, however; instead of showing 'Branch' in a Headquarter column, he wants the value ('HDQ, and the city of HQ + State). Is it even possible? I can't think of anything.

You've been around long enough to know that a picture is not consumable data.

Drew

J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
How to post data/code on a forum to get the best help.
How to Post Performance Problems
Make sure that you include code in the appropriate IFCode tags, e.g. [code=sql]<your code here>[/code]. You can find the IFCode tags under the INSERT options when you are writing a post.
NewBornDBA2017
NewBornDBA2017
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3679 Visits: 913
Had to ask. Thanks.
drew.allen
drew.allen
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62346 Visits: 16632
SELECT *, 
MAX(CASE WHEN [Headquarters or Branch] = 'Headquarters' THEN 'HDQ, and the city of ' + BusinessCity + ', ' + State' END) OVER( PARTITION BY CompanyName) AS HQ
FROM YourTableNameHere


Drew


J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
How to post data/code on a forum to get the best help.
How to Post Performance Problems
Make sure that you include code in the appropriate IFCode tags, e.g. [code=sql]<your code here>[/code]. You can find the IFCode tags under the INSERT options when you are writing a post.
NewBornDBA2017
NewBornDBA2017
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3679 Visits: 913
Thanks Drew for the query, worked beautifully. My development skills are still in developing stage so I am not sure what this query is doing even though it is working. Can you please help me understand?

select [Country]
,[CompanyName]
,[Headquarters or Branch]
,[BusinessCity]
,[State] as BusinessState
,MailingCity
,MailingState
,[PMGPIN]
, MAX(CASE WHEN [Headquarters or Branch] = 'Headquarters' THEN 'HDQ, ' + MailingCity + ', ' + MailingState
end)
OVER( PARTITION BY CompanyName) AS HQ
FROM [PMG].[PMGDataforbook]
where CompanyName like 'Allen Lund Company L%'

Attachments
Headquarter.PNG (5 views, 45.00 KB)
NewBornDBA2017
NewBornDBA2017
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3679 Visits: 913
I did understand the concept. Thanks a lot. I appreciate it.
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