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 2005 Forums
 Transact-SQL (2005)
 [HELP] SUM & REPLACE
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

knockyo
Yak Posting Veteran

83 Posts

Posted - 01/19/2010 :  04:02:34  Show Profile  Reply with Quote
Hi all,

I have a problem for the SUM and REPLACE function, the SQL script will as below,


select	DISTINCT 
	  CapitalForecastID 
	  ,Description 
	  ,BudgetOwnerName 
	  ,CapitalForecastCostPerUnit
	  ,' + @SelectColNames + '
	  SUM(' + @SelectColNames + ') AS TotalCost


for the @SelectColNames parameter will return the result as

[Q1 '10]       ,[Q2 '10]       ,[Q3 '10]       ,[Q4 '10]       ,


My Question as below,
(1) How can i SUM all the Quarters as above with the REPLACE symbol (+)

(2) Since from the statement above, i have symbol (') and (,). So i cant write the correct way on that.

Please advice.

Thanks :)

Edited by - spirit1 on 01/19/2010 04:27:13

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 01/19/2010 :  04:06:33  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

knockyo
Yak Posting Veteran

83 Posts

Posted - 01/19/2010 :  04:16:48  Show Profile  Reply with Quote
any hints from the references URL there?

Edited by - spirit1 on 01/19/2010 04:27:41
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11750 Posts

Posted - 01/19/2010 :  04:29:11  Show Profile  Visit spirit1's Homepage  Reply with Quote
removed the big annoying picture ads.

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.7 out!
Go to Top of Page

knockyo
Yak Posting Veteran

83 Posts

Posted - 01/19/2010 :  04:31:59  Show Profile  Reply with Quote
any ideas about the issues?
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11750 Posts

Posted - 01/19/2010 :  05:02:50  Show Profile  Visit spirit1's Homepage  Reply with Quote
your question isn't really clear. you're trying to create a delimited string of some sort?

provide DDL, sample DML and expected results from that DML for your problem and you'll get the answer sooner.

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.7 out!
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