开发者

SQL Server, Oracle8i syntax

开发者 https://www.devze.com 2023-01-22 09:00 出处:网络
I am running the simple query below select\'\'\'\' + event_number + \'\'\'\' +\',\' as Event_N from mytable

I am running the simple query below

select  '''' + event_number + '''' +',' as Event_N
from mytable

which gives:

Event_N
---------------
'BAB0910000001',
'CDD0910000002',
'ODB0910000002',
'YDB0910000003',
'NYC0910000004',

Question 1: Is there a way in SQL that can show the result as:

Event_N
'BAB0910000001','CDD0910000002','ODB0910000002','YDB0910000003','NYC0910000004',

I could do a dirty step by pressing Delte and End but would not be efficient when more than 100 records.

I am using Aqua Data Studio 7.5.34 and the back end is MS SQL Server 2000/5/8.

Event_number data type is varchar.

Question 2: But when I tried to run this query, it showed me the error below. Could someone please help!!!

select  '''' + event_key + '''' +',' as Event_K
from mytable

I am using Aqua Data Studio 7.5.34 and the back end is MS SQL Server 2000/5/8.

--event_key data type is int.

[Error] Script lines: 1-3 -------------------------- Conversion failed when converting the varchar value ''' to data type int. Msg: 2开发者_C百科45, Level: 16, State: 1, Procedure: , Line: 1


I ran the following query, which gives:

select ''''||EVENT_KEY||'''' as Event_K
from mytable

EVENT_K
'28732033'
'28797708'
'28796943'
'28133100'
'28718239'

Question 3: Is there a way in SQL that could add a comma (,) to the end of these records and output the result similar to question 1?

I am using Aqua Data Studio 7.5.34 and the back end is oracle 8i


Question 1 and 3 - essentially the same as this question: Use SQL instead of Delete and End from keyboard

OMG Ponies' post includes links to a selection of techniques in Oracle, as well as SQLServer.

Question 2 requires an explicit CAST or CONVERT on the event_key, to change it into character instead of numeric data - like so:

select  '''' + convert(varchar,event_key) + '''' +',' as Event_K
from mytable
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号