Hi i need some help in a Query,
i have a table
Table1 ( field1) with values 1,2,3,4 in the field 1.
when i run,
select field1 from table1
the query returns
1
2
3
4
but instead i need to get these values comma seperated
like 1,2,3,4. i dont want to use cursors for this.
can somebody help me in this.
thanks in advance.
sathyaHi
The only safe way is to use a cursor, alternatively the better method it to
do it on the client or a third party tool such as http://rac4sql.net/
John
"sathya" <softwaremaniac@.hotmail.com> wrote in message
news:060901c38bfc$65979c00$a001280a@.phx.gbl...
> Hi i need some help in a Query,
> i have a table
> Table1 ( field1) with values 1,2,3,4 in the field 1.
> when i run,
> select field1 from table1
> the query returns
> 1
> 2
> 3
> 4
> but instead i need to get these values comma seperated
> like 1,2,3,4. i dont want to use cursors for this.
> can somebody help me in this.
> thanks in advance.
> sathya|||Isn't this something cool:
declare @.List varchar(1000)
select @.List = coalesce(@.List + ',', '') + ltrim(rtrim(col1)) from table1
select @.List
hth
Quentin
"sathya" <softwaremaniac@.hotmail.com> wrote in message
news:060901c38bfc$65979c00$a001280a@.phx.gbl...
> Hi i need some help in a Query,
> i have a table
> Table1 ( field1) with values 1,2,3,4 in the field 1.
> when i run,
> select field1 from table1
> the query returns
> 1
> 2
> 3
> 4
> but instead i need to get these values comma seperated
> like 1,2,3,4. i dont want to use cursors for this.
> can somebody help me in this.
> thanks in advance.
> sathya|||Hi
This solution has been suggested by many people in the past (including
myself) but it is not a safe solution.
John
"Quentin Ran" <ab@.who.com> wrote in message
news:%23AGtH7CjDHA.360@.TK2MSFTNGP10.phx.gbl...
> Isn't this something cool:
> declare @.List varchar(1000)
> select @.List = coalesce(@.List + ',', '') + ltrim(rtrim(col1)) from table1
> select @.List
> hth
> Quentin
>
> "sathya" <softwaremaniac@.hotmail.com> wrote in message
> news:060901c38bfc$65979c00$a001280a@.phx.gbl...
> > Hi i need some help in a Query,
> >
> > i have a table
> >
> > Table1 ( field1) with values 1,2,3,4 in the field 1.
> >
> > when i run,
> >
> > select field1 from table1
> > the query returns
> > 1
> > 2
> > 3
> > 4
> >
> > but instead i need to get these values comma seperated
> > like 1,2,3,4. i dont want to use cursors for this.
> >
> > can somebody help me in this.
> > thanks in advance.
> >
> > sathya
>|||hi john,
What is the problem you are expecting
for me is in a loop, if i use it will slow down the
process.
it works fine for me
thanks
>--Original Message--
>Hi
>This solution has been suggested by many people in the
past (including
>myself) but it is not a safe solution.
>John
>"Quentin Ran" <ab@.who.com> wrote in message
>news:%23AGtH7CjDHA.360@.TK2MSFTNGP10.phx.gbl...
>> Isn't this something cool:
>> declare @.List varchar(1000)
>> select @.List = coalesce(@.List + ',', '') + ltrim(rtrim
(col1)) from table1
>> select @.List
>> hth
>> Quentin
>>
>> "sathya" <softwaremaniac@.hotmail.com> wrote in message
>> news:060901c38bfc$65979c00$a001280a@.phx.gbl...
>> > Hi i need some help in a Query,
>> >
>> > i have a table
>> >
>> > Table1 ( field1) with values 1,2,3,4 in the field 1.
>> >
>> > when i run,
>> >
>> > select field1 from table1
>> > the query returns
>> > 1
>> > 2
>> > 3
>> > 4
>> >
>> > but instead i need to get these values comma
seperated
>> > like 1,2,3,4. i dont want to use cursors for this.
>> >
>> > can somebody help me in this.
>> > thanks in advance.
>> >
>> > sathya
>>
>
>.
>
Showing posts with label field1. Show all posts
Showing posts with label field1. Show all posts
Wednesday, March 28, 2012
Wednesday, March 21, 2012
Query for Difference between two Fields
Can anyone please help me to find the diffence between two fields.
Field1 - 16:12:27:123
Field2 - 16:12:36:750
I need to find the difference between field2 and field1??Looks to me like the difference is 9:627 !
;)
When you say you need to find the difference, are you talking about determining that they ARE different, or finding the elapsed time?
If it's the latter, take a look into DATEDIFF in BOL...
Also, it would help if you tell us what type of field you have there...as that would also effect the answer.|||I need to find the the difference between two times.
Data Types - Field1 and Field2 are both nvarchar|||Look up DATEDIFF in BOL for starters...
DATEDIFF(ms, Field1, Field2)|||DECLARE @.foo NVARCHAR(50)
, @.bar NVARCHAR(50)
SET @.foo = N'16:12:27:123'
SET @.bar = N'16:12:36:750'
IF 0 = IsDate(@.foo)
PRINT 'foo is not a date'
IF 0 = Isdate(@.bar)
PRINT 'bar is not a date'
ELSE
SELECT DateDiff(ms, @.foo, @.bar)-PatP|||http://weblogs.sqlteam.com/jeffs/archive/2007/07/03/60248.aspx
Well worth a read.sql
Field1 - 16:12:27:123
Field2 - 16:12:36:750
I need to find the difference between field2 and field1??Looks to me like the difference is 9:627 !
;)
When you say you need to find the difference, are you talking about determining that they ARE different, or finding the elapsed time?
If it's the latter, take a look into DATEDIFF in BOL...
Also, it would help if you tell us what type of field you have there...as that would also effect the answer.|||I need to find the the difference between two times.
Data Types - Field1 and Field2 are both nvarchar|||Look up DATEDIFF in BOL for starters...
DATEDIFF(ms, Field1, Field2)|||DECLARE @.foo NVARCHAR(50)
, @.bar NVARCHAR(50)
SET @.foo = N'16:12:27:123'
SET @.bar = N'16:12:36:750'
IF 0 = IsDate(@.foo)
PRINT 'foo is not a date'
IF 0 = Isdate(@.bar)
PRINT 'bar is not a date'
ELSE
SELECT DateDiff(ms, @.foo, @.bar)-PatP|||http://weblogs.sqlteam.com/jeffs/archive/2007/07/03/60248.aspx
Well worth a read.sql
Subscribe to:
Posts (Atom)