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 2008 Forums
 Transact-SQL (2008)
 Query to Display only required text from column

Author  Topic 

dimepop
Starting Member

33 Posts

Posted - 2012-08-07 : 08:11:30
Hi,
I run a query against a SQL table in order to display some reports.

USE reports
SELECT device, message

from eventlogs


The problem is that instead of returning the full message of the column i only what something specific.
For example in the following DB
Device Message
------ --------
server1 | Failed events: The drive on 'server1' at '\\server1\E$' is 96.91% full which exceeds the limit of 95%. Successful Events: The drive on 'server1' at '\\server1\C$' is 63.80% full which is under the limit of 95%.

How can i make it so on the message column only returns the following values?
Device Message
------ -------
Server1 E$=96.91%; C$=63.80%

It would be event better that if the value in under 95% then no need to show it.

Thanks

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-08-07 : 08:14:56
Use SUBSTRING() and CHARINDEX() functions


--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

dimepop
Starting Member

33 Posts

Posted - 2012-08-07 : 09:20:45
I will look into it,
thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-07 : 10:15:51
so far as the format is consistent you can devise a logic using functions above. so in case of inconsistent formats you might have to break it down into batches and apply separate logic to handle each batch

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -