SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

keka3309
Starting Member

11 Posts

Posted - 04/03/2013 :  09:20:51  Show Profile  Reply with Quote
Hi All,

I go the data in the below format


A1 B1 C1
V0 13.5 13.5/13.9/14/16
V0 13.9 13.5/13.9/14/16
V0 14.0 13.5/13.9/14/16
V0 16.0 13.5/13.9/14/16
V1 15.0 10/12/15/16
V1 16.0 10/12/15/16
V1 12.0 10/12/15/16
V1 10.0 10/12/15/16


A1 and B1 are the columns wich i have in my table. I have to derive a new column C1 which should be grouped by A1 but the values in B1 need to concatenated instead of sum. Is this Possible.

Any help is much appreciated

Thanks

KEKA

James K
Flowing Fount of Yak Knowledge

3742 Posts

Posted - 04/03/2013 :  10:04:51  Show Profile  Reply with Quote
select
	a.A1,
	a.B1,
	STUFF((select '/' as [text()],B1 as [text()] from Table1 b
	where b.A1 = a.A1
	for xml path('')),1,1,'') as C1
from
	Table1 a
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/03/2013 :  13:55:24  Show Profile  Reply with Quote
quote:
Originally posted by James K

select
	a.A1,
	a.B1,
	STUFF((select '/'  + CAST(B1 AS varchar(10)) as [text()] from Table1 b
	where b.A1 = a.A1
	for xml path('')),1,1,'') as C1
from
	Table1 a




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3742 Posts

Posted - 04/03/2013 :  14:21:07  Show Profile  Reply with Quote
Both should be functionally (and for the most part performance-wise) the same. I am guessing though because I don't know whether extracting the inner text from the XML is more (or less) expensive than casting the float/decimal to varchar(10).
Go to Top of Page

keka3309
Starting Member

11 Posts

Posted - 04/04/2013 :  03:47:52  Show Profile  Reply with Quote
Thanks James and Vishak for your response

with out Cast My output is 0.000000000000000e+000,1.300000000000000e+001

after applying Cast my output is 0,13

Thanks
Keka
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/04/2013 :  05:44:42  Show Profile  Reply with Quote
quote:
Originally posted by keka3309

Thanks James and Vishak for your response

with out Cast My output is 0.000000000000000e+000,1.300000000000000e+001

after applying Cast my output is 0,13

Thanks
Keka


yep.
that was why i did the cast

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000