Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 17th, 2004, 06:01 PM
Slow2Code Slow2Code is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: B.C., Canada
Posts: 2 Slow2Code User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Help with mulit-join SQL

Hello,

I know there must be a SQL statement (using MS SQL server 2000) that could be created without having to create a VB program to do the same thing (which I have already started, since I suck at writing complex SQL). I tried doing this in Crystal Reports 8 but found that too frustrating. Any help is appreciated, anyways here are the three tables and fields in question:

INVMAST.................... INVLOC................. INVMSPEC
itemkey (pk)------> itemkey* (pk) --> itemkey* (pk)
specgrav............... location (pk) .......propnum (pk)
............................stdcost ..............propval


*indexed with duplicates, hence are part of a combined primary key in their respective table.

Required report (sorted by itemkey):
itemkey stdcost1 stdcost2 stdcost3 calcval1 calcval2 calcval3 calcval4 specgrav


Expressions:
stdcost1 = (stdcost WHERE location = '1')
stdcost2 = (stdcost WHERE location = '2')
stdcost3 = (stdcost WHERE location = '3')
calcval1 = (1-(propval WHERE propnum = 4))*100
calcval2 = (1-(propval WHERE propnum = 3))*100
calcval3 = (propval WHERE propnum = 6) * 100
calcval4 = (propval WHERE propnum = 5) * 100


Example
INVMAST: itemkey specgrav
.................AB1...... 0.6
.................AB2...... 0.5


INVLOC: itemkey location stdcost
.............. AB1 ..... 1 .... 4.00
.............. AB1 ..... 2 .... 4.25
.............. AB1 ..... 3 .... 4.50
.............. AB2 ..... 1 .... 3.50
.............. AB2 ..... 2 .... 3.75
.............. AB2 ..... 3 .... 4.00


INVMSPEC: itemkey propnum propval
.................. AB1 ..... 3 ...... 0.2
.................. AB1 ..... 4 ...... 0.22
.................. AB1 ..... 5 ...... 0.25
.................. AB1 ..... 6 ...... 0.3
.................. AB2 ..... 3 ...... 0.1
.................. AB2 ..... 4 ...... 0.15
.................. AB2 ..... 5 ...... 0.21
.................. AB2 ..... 6 ...... 0.35


with final report looking like
itemkey stdcost1 stdcost2 stdcost3 calcval1 calcval2 calcval3 calcval4 specgrav
AB1 ....... 4.00 ..... 4.25 ..... 4.50 ..... 78.0 .... 80.0 ..... 30.0 .... 25.0 ... 0.6
AB2 ....... 3.50 ..... 3.75 ..... 4.00 ..... 85.0 .... 90.0 ..... 35.0 .... 21.0 ... 0.5


Clear as mud?
Anyways easily done using VB, but just thought it would be so much quicker with just using a SQL statement.
Excuse the dots, but spacing just does not want to work properly :P

Last edited by Slow2Code : March 17th, 2004 at 06:16 PM. Reason: spacing blah!! 3rd try

Reply With Quote
  #2  
Old March 17th, 2004, 09:37 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Please read the forum rules first. Code should be placed in code tags. It is not advisable to post your entire message using BOLD either.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Help with mulit-join SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway