473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Staging the Value

benchpolo
142 100+
Data:
Acct Value
00011 Dermatologist
00011 Oncology
00011 General
00012 Part A
00012 Part B
00012 Part C

Question?
How can I stage the above data where the value will appear in the same line (see below)

00011 | Dermatologist | Oncology | General
00012 | Part A | Part B | Part C

Thanks.
Feb 6 '08 #1
3 1056
ck9663
2,878 Expert 2GB
you need a PIVOT table query...

check this post

-- ck
Feb 7 '08 #2
benchpolo
142 100+
Actually, it is more like a SQL Scripting bec. i'm pulling data from our server table.
Feb 7 '08 #3
deepuv04
227 Expert 100+
Actually, it is more like a SQL Scripting bec. i'm pulling data from our server table.

hi,
you can do this using function as


-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION fun
(
@acct varchar(10)
)
RETURNS varchar(max)
AS
BEGIN
-- Declare the return variable here
declare @value varchar(max)


DECLARE @TABLE TABLE
( ID INT identity(1,1),Acct VARCHAR(10),Value VARCHAR(100))
INSERT INTO @Table (Acct,Value)
SELECT Acct,Value FROM T1 WHERE Acct = @acct

select @value = ' '

DECLARE @MIN INT,@MAX INT
SELECT @MIN = min(id),@max = max(id) from @table
while( @min <= @max)
begin
--select @value = @value + '''' + Acct + ''',''' + [value] + ''' UNION select '
select @value = @value +'''' + [value] +''','
from @table
where id = @min
set @min = @min + 1
end

return SUBSTRING(@value,0,LEN(@VALUE))
END
GO



DECLARE @STRING VARCHAR(MAX)

SET @STRING = ''
SELECT @STRING = @STRING + 'SELECT '+ ACCT +','+ dbo.fun(acct) + ' UNION '
FROM T1
GROUP BY ACCT

--PRINT @STRING

SELECT @STRING = SUBSTRING(@String,0,len(@String) - (len('UNION')))
EXEC (@STRING)


this query will work only if each acct has equal number of rows. change this query according to your requirement.

thanks
Feb 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: jason | last post by:
What is the best way to allow a second developer access to existing html and asp files in the office from a development point of view. At the moment, I have been developing locally and then...
16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
7
by: Zri Man | last post by:
I have searched far and wide (not wide enough some might chip in) but cannot find the syntax for creating a staging table for an MQT. IBM manuals talk long and longer in serveral sections of this...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
0
by: Joe | last post by:
Does anyone know of a tool that can automate code migration from a staging server to a production server. As a developer I only have rights to migrate to staging and I would like a tool that could...
2
by: rom | last post by:
what do i have to more from staging to production every time i make changes? all the files only? what about the dll in the bin directory? if i copy the dll file do i also have to copy the aspx and...
6
by: Klemens | last post by:
I want to create an MQT, intialize it manually and then use staging table to refresh it with new data, but i don' t see a way for not doing full refresh after creating the staging table. I tried...
0
by: tshad | last post by:
I am trying to find the best way to handle my development process. I am using Dreamweaver to handle the check-in/check-out process which works pretty well. We are trying to work out the best...
2
by: cagi | last post by:
Hi to all, this is my first post here so I'm hoping you can help me. Now I'm writing a app which, among all other things need to record some data to CD. I'm using IMAPI v1 and here is the problem: i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.