473,402 Members | 2,064 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,402 software developers and data experts.

Dynamically input columns feilds in a select stmt

declare @qtr1 varchar(100)
set @qtr1='q107,q207'
-- this is an array input from the parameters selected on the front end of an application (q107,q207 are the quarters choosen) The number of quarters may vary based on selection.

select seller,sum(q107) q107,sum(q207) q207 from table_Seller
group by seller
having sum(q107+q207) <> 0

plz tel me how to dynamically generate the format "sum(q107) q107,sum(q207) q207 " in a select stmt in MSSQL 2005 server.
Jun 25 '07 #1
3 1273
Motoma
3,237 Expert 2GB
declare @qtr1 varchar(100)
set @qtr1='q107,q207'
-- this is an array input from the parameters selected on the front end of an application (q107,q207 are the quarters choosen) The number of quarters may vary based on selection.

select seller,sum(q107) q107,sum(q207) q207 from table_Seller
group by seller
having sum(q107+q207) <> 0

plz tel me how to dynamically generate the format "sum(q107) q107,sum(q207) q207 " in a select stmt in MSSQL 2005 server.

How are you getting those values in the first place?
Jun 25 '07 #2
How are you getting those values in the first place?
the values are from the fornt end of an application there are check boxes for q107,q207,q307 etc.
the database has vales for these quarters .But the quarters have to be displayed in pivot format.
Jul 3 '07 #3
srinit
43
declare @qtr1 varchar(100)
set @qtr1='q107,q207'
-- this is an array input from the parameters selected on the front end of an application (q107,q207 are the quarters choosen) The number of quarters may vary based on selection.

select seller,sum(q107) q107,sum(q207) q207 from table_Seller
group by seller
having sum(q107+q207) <> 0

plz tel me how to dynamically generate the format "sum(q107) q107,sum(q207) q207 " in a select stmt in MSSQL 2005 server.

hi use this code
[code]



while(charindex(',',@qtr1)>0)
begin
set @abc=charindex(',' ,@qtr1)
set @xyz=@xyz+''+'sum('+left(@qtr1,@abc-1)+') ' +left(@qtr1,@abc-1)
set @qtr1=right(@qtr1,len(@qtr1)-@abc)
set @lmn=@lmn+'+'+left(@qtr1,@abc-1)
end
set @xyz=@xyz+''+'sum('+@qtr1+') '@qtr1
exec('select '+@xyz+' from table_Seller
group by seller
having sum(@lmn))
Jul 3 '07 #4

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

Similar topics

3
by: Dave Nouwens | last post by:
Hi All, Please accept my appologies in advance for what I expect will be a reasonably simple question. I have an html form (which is generated in php) which contains a number of rows (one row...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
2
by: bruno | last post by:
I'm trying to dynamicaly change Where conditions in a Datagrid without success. The aspx form has some input fields, used to build the search, plus a final SEARCH button. In the click event I build...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
0
by: jad2006 | last post by:
i created CREATE PROCEDURE SP_STMT_STMTRETRIEVE10(IN p_client_id varchar(32) ,IN p_TIN varchar(32)) P1: BEGIN DECLARE p_customer_id varchar(32); DECLARE stmt VARCHAR(100); DECLARE cursor1...
1
by: reap76 | last post by:
I am trying to create a table that has two columns. If possible I'd like to do that usign two seperate INSERT statements. I am a complete rookie at sql and am learning as I go along. So, please...
2
by: punitshrivastava | last post by:
hello friends, i m working in php .i wsnt to know about feild validations .As i want to select data from combobox .according to that selected data feilds is to be editable Say for example : In...
1
by: hello2008 | last post by:
Hi, I have just started coding in PHP. I have coded a web page using HTML, JS, and PHP. An HTML table has to be populated dynamically using the data from the backend. Presently I have 5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.