+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 21 to 30 of 38

Thread: Design help-can this be done?

  1. #21
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Must be where I got the idea. I can hardly remember this morning, and that was near two weeks ago.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  2. #22
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    @R
    You data is probably going to be returned as rows and you will needs to 'pivot' the data into columns. For example consider the following ABLE data:
    Code:
    Prod Year Month Sales
    ABLE 2008 11 223
    ABLE 2008 12 252
    ABLE 2009 1  125
    ABLE 2009 2  435
    
    Which you will no doubt want to display Excel like:
    Code:
    Prod NOV08 DEC08 JAN09 FEB09
    ABLE   223   252   125   435
    
    SQL2005 has the PIVOT verb, but you don't have that so it's a bit more complicated. Probably going to require some dynamic SQL in a stored proc. The SQL for the above would be something like
    Code:
    Select Prod
          sum(case when Year = 2008 and Month = 11 then Sales else null end) as 'Nov08',
          sum(case when Year = 2008 and Month = 12 then Sales else null end) as 'Dec09',
          sum(case when Year = 2009 and Month = 1 then Sales else null end) as 'Jan09',
          sum(case when Year = 2009 and Month = 2 then Sales else null end) as 'Feb09'
    From myTable
    
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #23
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Quote Originally Posted by Wolffy View Post
    @R
    You data is probably going to be returned as rows and you will needs to 'pivot' the data into columns. For example consider the following ABLE data:
    Code:
    Prod Year Month Sales
    ABLE 2008 11 223
    ABLE 2008 12 252
    ABLE 2009 1  125
    ABLE 2009 2  435
    
    Which you will no doubt want to display Excel like:
    Code:
    Prod NOV08 DEC08 JAN09 FEB09
    ABLE   223   252   125   435
    
    SQL2005 has the PIVOT verb, but you don't have that so it's a bit more complicated. Probably going to require some dynamic SQL in a stored proc. The SQL for the above would be something like
    Code:
    Select Prod
          sum(case when Year = 2008 and Month = 11 then Sales else null end) as 'Nov08',
          sum(case when Year = 2008 and Month = 12 then Sales else null end) as 'Dec09',
          sum(case when Year = 2009 and Month = 1 then Sales else null end) as 'Jan09',
          sum(case when Year = 2009 and Month = 2 then Sales else null end) as 'Feb09'
    From myTable
    
    Ok, don't have 2005 but I'll give that a try in sql2000 with my query/view. oh oh...then this means each time a new month is added I have to change/update the view/query?

    Quote Originally Posted by Wolffy View Post
    After further thought, store the date values as DateTimes, but then use the Month() and Year() functions in the queries and in the reports.

    Not sure what your data means -- what do the fields ActualVal and RevenueAmt mean?



    For each record will ActualDt and RevenueDt be the same Month and Year? If not, in what Year/Month will it be reported?
    in the actual table, actualval is just the value (int4) that is actual # for the month but there are multiple job categories for each location so each will have its own. I have built the forecast table which will have a forecastvalue also but just want to get started with the actual first to see if i can doit.

    each location will have approx 19 jobcategories for each month, so yes the date(month/year)field will be repeated 19 times.
    the RevenueDt stands for Revenue date, this exists in my tblRevenue...for this there will only be 1 revenue value for each location each month.

  4. #24
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Ok, don't have 2005 but I'll give that a try in sql2000 with my query/view. oh oh...then this means each time a new month is added I have to change/update the view/query?
    No, not really. Either use Dynamic SQL in a stored procedure, or a query such as
    Code:
    Select item ,
     sum(case 
        when Month(recDate) = Month(dateadd(mm, -3, getdate()) 
           and Year(recDate) = Year(dateadd(mm, -3, getdate())
          then Sales
          else Null) as ThreeMonthsAgo ,
     sum(case
       when Month(recDate) = Month(dateadd(mm, -2, getdate())
         and year(recDate) = year(dateadd(mm, -2, getdate())
        then Sales
        else Null) as TwoMonthsAgo 
     -- etc. for all Past, Current and Future Dates
    From myTable
    
    Yes, it's a big ugly query -- nobody said it would be easy.

    Worry about setting the column names then in the ASP page rather than the query.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  5. #25
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    need some help here...

    I have this but getting error about incorrect syntax near 'then'. I've highlighted in blue, line 3 where the issue is.
    Code:
    SELECT     dbo.tblHRLocation.LocID, dbo.tblHRLocation.Location, dbo.tblJobCategory.JobDescID, dbo.tblJobCategory.JobDesc, dbo.tblHRActual.HRActualDt, 
                          dbo.tblHRActual.HRActual,
    sum(case when Month(dbo.tblHRActual.HRActualDt) = Month(dateadd(mm, -3, getdate()) then dbo.tblHRActual.HRActual else null) as ThreeMonthsAgo
    FROM         dbo.tblHRActual INNER JOIN
                          dbo.tblHRRevenue ON dbo.tblHRActual.HRActualDt = dbo.tblHRRevenue.RevenueDt LEFT OUTER JOIN
                          dbo.tblHRLocation ON dbo.tblHRRevenue.LocID = dbo.tblHRLocation.LocID AND dbo.tblHRActual.LocID = dbo.tblHRLocation.LocID LEFT OUTER JOIN
                          dbo.tblJobCategory ON dbo.tblHRActual.JobDescID = dbo.tblJobCategory.JobDescID
    WHERE     (dbo.tblHRLocation.LocID = 1)
    

  6. #26
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    You are missing the right paren on the second Month function and the END for the Case statement.

    I find it super helpful to check the query in the Query Analyzer (Management Studio in 2005) by putting each part of the statement on a different line -- that way the error message points right at the error (usually)
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  7. #27
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    okies...Thank you very much! after that needed group by...got that added now i can see results. Gonna go add the rest of the months.

    w00t!


  8. #28
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Quote Originally Posted by Wolffy View Post
    Worry about setting the column names then in the ASP page rather than the query.
    A little confused about this statement above...

    I've got the 3 actual month query setup as in your example and its looking good.

  9. #29
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Just mean there is no good reason why the column name returned from the query must be the name of the column in the report generated by ASP. The query can return a column called 'ThisMonth' whilst the report can figure out that 'ThisMonth' is really 'SEP09'.

    Heck, name the columns 0 through 11 and then generate an array of column names such that ColumnName[0] is 'May09', ColumnName[1] is 'Jun09', etc.

    I should also add that the query in my previous post has to be run the the current month (i.e. for September, it has to be run in September) cuz of the getdate() function. If you want a query that can be run for any previous month, then you are probably looking at some Dynamic SQL in a stored procedure. (Same query, but replace getdate() is a variable such as @rptDate)
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  10. #30
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Ok, I didn't know if you were trying to tell me only do so much in sql and do most in asp...got ya now.

    I've been trying to put it all together in analyzer but I'm having trouble when
    I bring in the tblForecast fields. My question is, should I be trying to put
    together here or leave separate?...ex, how i want to be displayed:

    Code:
    fieldcategoriesnames - last 3mo actuals - current mo and 9 mos. out
    name1 - jun09 - jul09 - aug09 - sep09 - oct09 -nov09...etc.
    

+ Reply to Thread
Page 3 of 4 FirstFirst 1 2 3 4 LastLast

Similar Threads

  1. Design/Logic Help
    By Rebelle in forum Database Design Help
    Replies: 5
    Last Post: March 24th, 2009, 02:05 PM
  2. Database Design
    By dtz in forum Database Design Help
    Replies: 15
    Last Post: March 13th, 2009, 08:55 AM
  3. help with form design
    By Ziggy in forum Microsoft Access
    Replies: 12
    Last Post: February 16th, 2009, 02:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO