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 |
jaskiew
Starting Member
4 Posts |
Posted - 2007-11-13 : 11:37:11
|
Hi,I am selecting a string as follows and was able to order by column vendor until I added a UNION statment. Now the order by will not work. Here is the query:select 'FM'+ (right(replicate(' ',6) + RIGHT(RTRIM(INVOICE),6),6)) + ' ' + '1' + LEFT(VENDOR,6) + (REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '')) + ' ' + '0112662260'+ (right(replicate(' ',10) + cast((convert(integer, (round(AMOUNT,2)* 100))) as varchar(10)),10))+ CD + CONVERT(CHAR(6),po_num)+ ' ' + 'QPR' + ' ' + (REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '')) + '25' as column1FROM DBO.MAC_PR_UPLOAD UNIONselect 'FM'+ (right(replicate(' ',6) + RIGHT(RTRIM(INVOICE),6),6)) + ' ' + '1' + LEFT(VENDOR,6) + (REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '')) + ' ' + '0112122127'+ (right(replicate(' ',10) + cast((convert(integer, (round(GST,2)* 100))) as varchar(10)),10))+ CD + CONVERT(CHAR(6),po_num)+ ' ' + 'QPR' + ' ' + (REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '')) + '25' as column1FROM DBO.MAC_PR_UPLOAD Sample result:FM 34605 1CA6680111307 0112662260 4398D34605 QPR 11130725FM 77058 1SE4611111307 0112122127 1423D34450 QPR 11130725FM 89845 1YO2488111307 0112122127 2603D34371 QPR 11130725and i want to order the string by characters 11 through 16.If this is possible can someone please help me out?Thanks.Linda |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-13 : 11:53:12
|
select * from(your query) as torder by cast(substring(column1,11,16) as bigint)MadhivananFailing to plan is Planning to fail |
 |
|
jaskiew
Starting Member
4 Posts |
Posted - 2007-11-13 : 12:54:00
|
Thanks so much! Perfect.Linda |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-14 : 03:00:39
|
quote: Originally posted by jaskiew Thanks so much! Perfect.Linda
Well. Why are you concatenting all the columns using sql?Where do you want to show the data?MadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-11-14 : 03:33:22
|
I think he need this for exporting to a fixed size text file. E 12°55'05.25"N 56°04'39.16" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-14 : 03:50:00
|
quote: Originally posted by Peso I think he need this for exporting to a fixed size text file. E 12°55'05.25"N 56°04'39.16"
Well. That makes sense MadhivananFailing to plan is Planning to fail |
 |
|
jaskiew
Starting Member
4 Posts |
Posted - 2007-11-14 : 11:45:46
|
Yes she does . Thanks again. |
 |
|
|
|
|
|
|