Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

T-SQL to get value on any given day Expand / Collapse
Author
Message
Posted Monday, July 28, 2014 4:14 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 3:19 PM
Points: 157, Visits: 608
Even with the...

AND CTE1.item = CTE2.item

...in the join?

It seemed to work okay. Did I screw something up?



"If I had been drinking out of that toilet, I might have been killed." -Ace Ventura
Post #1597109
Posted Monday, July 28, 2014 4:29 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 15, 2014 2:26 PM
Points: 5,466, Visits: 7,647
autoexcrement (7/28/2014)
Even with the...

AND CTE1.item = CTE2.item

...in the join?

It seemed to work okay. Did I screw something up?


Hrm, good point, my apologies. I read it too quickly. Habit on my part to make sure I don't screw up the partitioning versus the ordering, but it works both ways.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1597113
Posted Monday, July 28, 2014 5:20 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 2:37 PM
Points: 867, Visits: 7,574
And another clarifying question:

Can a value change twice in a day such that there will be 2 values of an item for a given day? If so, how will you know which one to return?




And then again, I might be wrong ...
David Webb
Post #1597120
Posted Tuesday, July 29, 2014 12:58 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, December 5, 2014 3:47 AM
Points: 56, Visits: 161
Thanks to everyone for your responses. Craig has the answer 'cos I'm used to using calendar tables. But I do like Autos cte as well - it's self-contained.

I appreciate your efforts and I will endeavour in future posts to make my questions un-ambiguous and as clear as possible.

You've made my day easier so I wish you all a good day too.
Post #1597163
Posted Tuesday, July 29, 2014 7:04 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:05 PM
Points: 13,327, Visits: 12,820
I see that several others jumped in and found you a working solution. Glad you were able to get it working and thanks to the others for jumping in.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1597268
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse