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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-02-07 : 10:19:17
|
| Jon writes "Hi!I have a little bit of a problem..I want to truncate a result from a query to some rules, and I can't figure out how to do that..Her it is..Let´s say I have a results that says ' the computer-name is computer02 and IP-number is 192.168.0.4'from that result I just want to have the computername..I have tried with select left, right but I only get the opposite results, I get the stuff that I want..select left(subject,22)+ ' This is what I want ' +right(subject,66) from mailHow do I do it?/Jon - DB-admin Landstinget Dalarna" |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-02-07 : 10:45:26
|
| Check for Case Statement in BooksOnline.--------------------------------------------------------------Dont Tell God how big your Problem is , Tell the Problem how Big your God is |
 |
|
|
ToddV
Posting Yak Master
218 Posts |
Posted - 2002-02-07 : 11:00:21
|
| There are a bunch of string functions that can help you do this. In its simplest:Select Substring(subject,22,11) FROm EmailIn a more complicated scenario. Say the name is always proceeded by 'computer-name is' and followed by a space:SELECT SUBSTRING(Subject, Patindex('%computer-name is%',Subject)+17, Charindex(Space(1), Subject,Patindex('%computer-name is%',Subject)+17 ) - (Patindex('%computer-name is%',Subject)+17))FROM EmailIf you had a list of possible machines you could join using Like operator (This could Join to more than one row)SELECT * FROM Email A JOIN Machine B ON Subject LIKE '%' + MachineName + '%' |
 |
|
|
|
|
|
|
|