Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JezEling
Starting Member
4 Posts |
Posted - 2005-08-31 : 11:31:46
|
| Hi All,I have been trying to create a query that will all me to extract data from a table and group the records retrieved into a single row based on date, for example: -Data1/1/2005 61/1/2005 101/1/2005 201/1/2005 301/2/2005 51/2/2005 61/3/2005 19Required Output from query1/1/2005 6 10 20 301/2/2005 6 61/3/2005 19Can anyone provide me with any assistance on this matter?Many thanks in advanceJez |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
|
|
magesh
Starting Member
23 Posts |
Posted - 2005-09-01 : 02:40:16
|
| Hi,you can do that using UDF..heres is an example with DDL and UDF---DDL----CREATE TABLE [UDFTBL] ( [DateCol] [datetime] NOT NULL , [IDCol] [int] NOT NULL , CONSTRAINT [PK_UDFTBL] PRIMARY KEY CLUSTERED ( [DateCol], [IDCol] ) ON [PRIMARY] ) ON [PRIMARY]GO---UDF-----CREATE FUNCTION SPACEID(@DATECOL DATETIME)RETURNS VARCHAR(1000)AS BEGINDECLARE @OUTPUT VARCHAR(100)SET @OUTPUT='' SELECT @OUTPUT = CASE @OUTPUT WHEN '' THEN CAST(IDCol AS VARCHAR(10)) ELSE @OUTPUT + ' ' + CAST(IDCol AS VARCHAR(10)) ENDFROM UDFTBL WHERE DateCol = @DATECOLORDER BY IDCOLRETURN @OUTPUTENDGO--------select DISTINCT DateCol,dbo.SPACEID(DateCol) AS IDVALFROM UDFTBLregardsMagesh |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-01 : 03:01:43
|
| In that topic given by Ajarn, I provided the link that does this by using FunctionMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|