Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 parsing one field into another field

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2010-08-30 : 18:23:19
I have the following query:
select p.portfolio,
mt.text
from [message] m
join message_type mt
on mt.id = m.message_type_id
left join portfolio p
on p.id = m.portfolio_id
left join security s
on s.id = m.security_id
left join benchmark b
on b.id = m.benchmark_id
left join holding h
on h.id = m.holding_id
left join transactions t
on t.id = m.transaction_id
where mt.id = '2008'


Sample output:
portfolio	text
9815T025020 Finished History Engine for portfolio ID %s.


looking to get output so that the text reads:

Finished History Engine for portfolio ID 9815T025020

another example would be:
select p.portfolio,
s.cusip,
cast(getdate() as SMALLDATETIME),
mt.text
from [message] m
join message_type mt
on mt.id = m.message_type_id
left join portfolio p
on p.id = m.portfolio_id
left join security s
on s.id = m.security_id
left join benchmark b
on b.id = m.benchmark_id
left join holding h
on h.id = m.holding_id
left join transactions t
on t.id = m.transaction_id
where mt.id = '2024'


output:
portfolio	cusip	(No column name)	text
9861E084027 USD 2010-08-30 Portfolio ID: %s History Rule: 5160 - Principal Value of holding is zero for Security ID %s on %s.


would want it to read:

Portfolio ID: 9861E084027 History Rule: 5160 - Principal Value of holding is zero for Security ID USD on 2010-08-30.

any suggestion on how i can insert the values into the static txt data replacing the %s would be greatly appreciated

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-30 : 18:25:40
You should not be doing this in T-SQL as this is a presentation issue. Return the raw data back to the application and do the formatting there.

If you must do this in T-SQL, which seems highly unlikely, then use the REPLACE function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2010-08-30 : 21:42:57
quote:
Originally posted by tkizer

You should not be doing this in T-SQL as this is a presentation issue. Return the raw data back to the application and do the formatting there.

If you must do this in T-SQL, which seems highly unlikely, then use the REPLACE function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



I'm looking to do it in a query to push back to SSRS. The vendor does a craptastic job today of displaying the log info in the app, so we are trying to come up with own solution
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-31 : 11:51:51
Do the formatting in SSRS, don't do it in T-SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -