Skip to main content
nikos101
Inspiring
November 11, 2008
Answered

Split Query needed please

  • November 11, 2008
  • 6 replies
  • 662 views
Whats the best way to select query of a columns with data like this:

GBP / USD

The result will look like this:

Cur1 Cur2
GBP USD
This topic has been closed for replies.
Correct answer
Something like this which will deal with leading and trailing blanks, miscellaneous blanks between the currency code and slash. If the slash can be missing this gets more complicated

ltrim(rtrim(substring(curs,1,charindex('/',cur)-1))) as Cur1

rtrim(ltrim(substring(curs,charindex('/',cur)+1,255))) as Cur2

This is really overkill if it's a fixed 3chars space slash 3chars then it's simply

substring(curs,1,3) as Cur1

substring(curs,6,3) as Cur2

6 replies

nikos101
nikos101Author
Inspiring
November 12, 2008
Thanks scottcook, very clever
Correct answer
November 11, 2008
Something like this which will deal with leading and trailing blanks, miscellaneous blanks between the currency code and slash. If the slash can be missing this gets more complicated

ltrim(rtrim(substring(curs,1,charindex('/',cur)-1))) as Cur1

rtrim(ltrim(substring(curs,charindex('/',cur)+1,255))) as Cur2

This is really overkill if it's a fixed 3chars space slash 3chars then it's simply

substring(curs,1,3) as Cur1

substring(curs,6,3) as Cur2
Inspiring
November 11, 2008
google "ms sql string functions" and look for things resembling substring, position, and length.
nikos101
nikos101Author
Inspiring
November 11, 2008
MS SQL
Inspiring
November 11, 2008
You could always use cold fusion on the results. Looks like a simple replace or listfirst/listlast.

If you are able to, normalize your database so you don't have problems like this.
Inspiring
November 11, 2008
depends on your db... which one are you using?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/