在查询列中添加文本

时间:2014-02-07 04:04:40

标签: sql

我有这个问题:

select PONUMBER from orderinfo where custid = 45203
and orderstatus = 'picked'
order by preparedate desc

输出是:

1
2
3
4
5

有没有办法做到这一点:

UPS  |  1
UPS  |  2
UPS  |  3
UPS  |  4
UPS  |  5

我基本上想要添加一个带静态字的列UPS。我将输出为CSV。

2 个答案:

答案 0 :(得分:2)

试试这个;

select 'UPS', PONUMBER 
from orderinfo where custid = 45203
and orderstatus = 'picked'
order by preparedate desc

答案 1 :(得分:0)

试试这个

如果你想要单独的列,那么试试这个

SELECT 'UPS',PONUMBER 
FROM orderinfo 
WHERE custid = 45203 AND orderstatus = 'picked'
ORDER BY preparedate desc

如果你想在同一列中找到它,那么试试这个

SELECT 'UPS  |' + CAST(PONUMBER AS VARCHAR(10)) 
FROM orderinfo 
WHERE custid = 45203 AND orderstatus = 'picked'
ORDER BY preparedate desc