sql server - Can I compare entries of a same table based on their different dates? -
i creating procedure receives 2 dates parameters.
the procedure works on table has following columns (i'd put picture of actual table don't have enough reputation yet):
date displayname label capacity
the data contained in table have been collected on few years , 1 day displayname columns refer the name of vmware. thus, possible start date has 3 entries , end date has 5 (reflecting vmwares created in between). follow. given start , end date, able select displayname (along label , capacity) have been created (or added if will) between 2 dates. have
create procedure affichercreationluns @start date, @end date begin select datecollecte, displayname, label, capacity vsp datecollecte = @end , displayname not in (select displayname vsp datecollecte = @start) end
this works if start date exact 1 vmware created (and displayname added entries). if pick date before nothing appears.
i have tried datecollecte >= @start , datecollecte < @end
but never worked no matter chosen dates.
i tried defining dates this
@start date = '2014-05-01', @end = '2014-05-02'
but doesn't change anything.
now not sure if can done, following:
- to show in date column of table not end date (like code there) date on vmware created (and entries added)
- to show displayname has been created if has been destroyed. i.e. if 10th have 3 entries, vmware created 12th (i have 4 entries date) , destroyed 13th, appear if selected dates start = 10th , end = 14.
thanks guys!
p.s. here structure of table if helps:
---------------- columns for: vsp ---------------- ----------dev_technowin dbo vsp id 4 int identity 10 4 0 10 0 4 1 no 56 ----------dev_technowin dbo vsp datecollecte -9 date 10 20 1 -9 2 yes 0 ----------dev_technowin dbo vsp displayname -9 nvarchar 250 500 1 -9 500 3 yes 39 ----------dev_technowin dbo vsp capacityinkb 6 float 15 8 10 1 6 4 yes 109 ----------dev_technowin dbo vsp consumedcapacityinkb6 float 15 8 10 1 6 5 yes 109 ----------dev_technowin dbo vsp dppoolid 4 int 10 4 0 10 1 4 6 yes 38 ----------dev_technowin dbo vsp label -9 nvarchar 250 500 1 -9 500 7 yes 39 ----------dev_technowin dbo vsp tieringpolicy 4 int 10 4 0 10 1 4 8 yes 38 ----------dev_technowin dbo vsp dptier0consumedcapacityinkb6 float 15 8 10 1 6 9 yes 109 ----------dev_technowin dbo vsp dptier1consumedcapacityinkb6 float 15 8 10 1 6 10 yes 109 ----------dev_technowin dbo vsp dptier2consumedcapacityinkb6 float 15 8 10 1 6 11 yes 109 ----------dev_technowin dbo vsp dateimport -9 date 10 20 1 -9 12 yes 0
try using between in case
create procedure affichercreationluns (@start date, @end date) begin select datecollecte, displayname, label, capacity vsp datecollecte between @end , @start end
by msdn
the query retrieves expected rows because date values in query , datetime values stored in ratechangedate column have been specified without time part of date. when time part unspecified, defaults 12:00 a.m. note row contains time part after 12:00 a.m. on 2002-01-05 not returned query because falls outside range.
Comments
Post a Comment