Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 25th, 2008, 06:13 AM
Registered User
 
Join Date: Jun 2008
Location: Hudson Line, Delhi, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to write T-SQL to retrieve the required Output

Hi all!

I am using tables "OptionsMapping" (Id, Category, Name), "Person" (Id, Name, Add etc) and "STRENGTHANDCONDITIONINGDAILY" (PersonId, Date, MorningId, AfterNoonId) to retrive required results through T-SQL.



OptionsMapping table



Id Category Name

1 1 Pre-activation

2 1 Lower Body Strength

3 1 Upper Body Strength





Person Table



Id Name Add

1 Amit New Delhi

2 Sachin New Delhi

3 Santosh New Delhi





STRENGTHANDCONDITIONINGDAILY



PersonId Date MorningID AfterNoonId

2 2008-06-23 00:00:00 1 2

2 2008-06-24 00:00:00 3 1

3 2008-06-23 00:00:00 2

3 2008-06-24 00:00:00 3 1







I want to output as follows with T-SQL -



Player Pre-Activation Lower Body Strength Upper Body Strength Total

Sachin 2 1 1 4

Santosh 1 1 1 3





In above, Except Player and Total headers all are comming dynamically from optionsMapping tables and it's calculated values are comming from "STRENGTHANDCONDITIONINGDAILY" table. How to calculate For example Person id 2 is Sachin has attempt option Pre-Activation 2 times, Lower Body Strength 1 times and Upper Body Strength 1 times. So total activity is 4. Similarlly for all person I want to display through T-SQL.



Please help me to write T-SQL?



Thanks in advance


Developer
Anil Dwivedi
Reply With Quote
  #2 (permalink)  
Old June 25th, 2008, 02:17 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

This could be really easy if you know ahead of time that you only care about ID's 1,2,3 in the OptionsMapping table. But assuming that this table is dynamic--that you can add new options in new categories at any time--then it's much much more difficult.

So... ARE the categories FIXED? Or do you need to handle dynamic mappings??

[ Your design for StrengthAndConditioningDaily is also less than ideal for the purposes of this task, but it's at least usable. ]
Reply With Quote
  #3 (permalink)  
Old June 26th, 2008, 12:15 AM
Registered User
 
Join Date: Jun 2008
Location: Hudson Line, Delhi, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Old Pedant
 This could be really easy if you know ahead of time that you only care about ID's 1,2,3 in the OptionsMapping table. But assuming that this table is dynamic--that you can add new options in new categories at any time--then it's much much more difficult.

So... ARE the categories FIXED? Or do you need to handle dynamic mappings??

[ Your design for StrengthAndConditioningDaily is also less than ideal for the purposes of this task, but it's at least usable. ]


First of all thanks for quickly reply....

So... ARE the categories FIXED? Or do you need to handle dynamic mappings??

No categories are not fixed. I need handle it dynamic mappings.

Here I want result(Output) columns except "Player" and "Total" columns all come dynamically from the OptionsMapping table.

If you are talking about "Cetegory" column of "OptionsMapping" table. It can be fixed if easier to implement T-SQL. Since I am inserting options in "STRENGTHANDCONDITIONINGDAILY" only for one category.But options are not fixed it can be any number for one cetegory.


Thanks a million ton



Developer
Anil Dwivedi
Reply With Quote
  #4 (permalink)  
Old June 26th, 2008, 12:37 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I think this will be really tough to do all in SQL.

The only way I see to do it is to first build the SQL statement needed to create a TEMP table with the appropriate columns. You do that by examining your OptionsMapping table for the given category.

And then you'll create one row in your TEMP table for each person from the Person table.

And then finally you'll have to run a cursor through the StrengthAndConditioningDaily table that UPDATEs the appropriate row and columns in the TEMP table.

This would be 10 times easier to code in some reporting system, such as ASP or PHP or JSP or ASP.NET, than it is in SQL code. *MUST* it be in T-SQL???
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL XML Explicit (Output file required) Neal SQL Server 2005 0 August 4th, 2008 03:04 AM
retrieve varbinary using StoredProc with OUTPUT ag19702004 ADO.NET 0 November 30th, 2005 01:37 PM
How to write a retrieve procedure... milindgpatil Oracle 2 August 9th, 2005 10:49 PM
how to write output to an external file pigtail Javascript 2 April 30th, 2004 09:34 AM
How to output Response.write to certain location alyeng2000 ASP.NET 1.0 and 1.1 Basics 3 December 9th, 2003 10:03 AM



All times are GMT -4. The time now is 08:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.