tags:

views:

32

answers:

1

Hi Folks,

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: 245, 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

+2  A: 

Question 1 and 3 - essentially the same as this question: http://stackoverflow.com/questions/4029129/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
Mark Bannister
Thanks, Mark! and everyone else.
Chris