+ Reply to Thread
Page 4 of 4 FirstFirst ... 2 3 4
Results 31 to 38 of 38

Thread: Design help-can this be done?

  1. #31
    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

    Consider doing a UNION of your tblActual and tblForcast in a View:
    Code:
    Create View tblAlldata as
    Select recDate, sales, 1 as isActual
      From tblActual
    UNION ALL
    Select recDate, sales, 0 as isActual
      From tblForecast
    
    Then use that view in your massive Select..SUM..Case query. You'll need to add the isActual flag to the Case's When clause:
    Code:
    sum (case when <3 months ago> and isActual = 1 then sales else null end) as ..
    :
    sum (case when <next month> and isActual = 0 then forecast else null end) as ..
    
    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. #32
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Okies, letting it all sink in...

    here is what I can run successfully in the analyzer but when i try to use the same exact thing and save as new view it will not let me.

    Code:
    SELECT     TOP 100 PERCENT dbo.tblHRActual.LocID, dbo.tblHRActual.HRActualDt, dbo.tblHRActual.HRActual, 1 as isActual
    from dbo.tblHRActual
    union all
    SELECT     TOP 100 PERCENT dbo.tblHRForecast.LocID,dbo.tblHRForecast.HRForecastDt, dbo.tblHRForecast.HRForecast, 0 as isActual
    from dbo.tblHRForecast
    
    Code:
    The Query Designer does not support the UNION SQL construct.
    

  3. #33
    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

    Ah, true. You can't do this is the Designer. Open a New Query end execute the following:
    Code:
    Create View vActualAndForcast -- or whatwever you want to name it
    As
    SELECT dbo.tblHRActual.LocID, dbo.tblHRActual.HRActualDt,
           dbo.tblHRActual.HRActual, 1 as isActual
           from dbo.tblHRActual
    union all
    SELECT dbo.tblHRForecast.LocID,dbo.tblHRForecast.HRForecastDt,
           dbo.tblHRForecast.HRForecast, 0 as isActual
           from dbo.tblHRForecast
    
    I think the Top 100 percent is superfluous here
    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.

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

    Hey w0lffy...

    I forgot a column in the new view your last post, is there a way to edit to add it? I tried properties but it didn't take it.

    Thanks!

  5. #35
    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

    Well in Management Studio, you would right click on the view name in the Object Explorer and select Script View As->Alter To->New Query Editor. I imagine there is something equivalent in Query Analyzer.

    Then make you changes and execute the script.
    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.

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

    Got that added w0lffy. Thanks!

    I have this line for the current month forecast, the records are showing correctly but wondered if this is the correct way to use 0?

    Code:
    sum(case when Month(dbo.vwHRPlan.HRActualDt) = Month(dateadd(mm, 0, getdate())) and Year(dbo.vwHRPlan.HRActualDt) = Year(dateadd(mm, 0, getdate())) and dbo.vwHRPlan.isActual = 0 then dbo.vwHRPlan.HRActual else Null END) as CurrMoFcast,
    

  7. #37
    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

    Why not just use Month(getdate()) and Year(getdate())?
    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.

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

    ok, i can do that.

+ Reply to Thread
Page 4 of 4 FirstFirst ... 2 3 4

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