gtsummary::tbl_uvregression for Poisson regression - gtsummary

I'm facing a problem when trying to implement the tbl_uvregression() for making a specific table summarizing univariable analysis I want to display for count regression with Poisson model.
I've a data frame named Data, my outcome is a count (anomalies_tot). I've also an offset nvx.
Data <- tibble::tribble(
~nvx, ~anomalies_tot, ~age_moyen, ~productivite,
1L, 2, "Entre 8 et 10 jours", "Entre 9 500 et 11 000 L/VL",
1L, 1, "Entre 8 et 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 3, "Plus de 10 jours", "Moins de 9 500 L/VL",
1L, 4, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 3, "Plus de 10 jours", "Moins de 9 500 L/VL",
2L, 3, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
2L, 5, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
2L, 1, "Moins de 8 jours", "Plus de 11 000 L/VL",
3L, 2, "Entre 8 et 10 jours", "Moins de 9 500 L/VL",
3L, 8, "Moins de 8 jours", "Moins de 9 500 L/VL",
1L, 3, "Moins de 8 jours", "Entre 9 500 et 11 000 L/VL",
1L, 2, "Entre 8 et 10 jours", "Moins de 9 500 L/VL",
5L, 12, "Moins de 8 jours", "Entre 9 500 et 11 000 L/VL",
1L, 2, "Entre 8 et 10 jours", "Moins de 9 500 L/VL",
3L, 2, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 3, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 5, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 2, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
3L, 5, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
11L, 26, "Moins de 8 jours", "Moins de 9 500 L/VL",
3L, 8, "Moins de 8 jours", "Entre 9 500 et 11 000 L/VL",
3L, 7, "Plus de 10 jours", "Plus de 11 000 L/VL",
1L, 0, "Plus de 10 jours", "Moins de 9 500 L/VL"
)
I've a specific vector of covariates u_var where:
u_var <- c("age_moyen", "productivite")
u_var is a vector of my covariates (I've only selected 2 of them)
I've also a specific offset = (nvx) that needs to be accounted for in my model.
I've initially run the univariable Poisson using lapply function:
lapply(u_var,
function(var) {
formula <- as.formula(paste("anomalies_tot ~", var, "+offset(log(nvx))"))
res.pois.uni <- glm(formula, data = Data, fam = poisson(link = log))
})
This work well but results are not displayed nicely for being reported in a white paper.
I would be very interested to display the univariable results of Poisson model for individual covariates included in u_var. My code I'm trying is not working and I don't know how to add information on my offset=log(offset)
`Data %>% dplyr::select(u_var, anomalies_tot, nvx) %>% tbl_uvregression(method = glm, y = anomalies_tot, method.args = list(family = "poisson"),
exponentiate = TRUE)`
Therefore I'm asking for any advice in how to produce a specific table of univariable Poisson analysis for all my variables u_var (unadjusted results) using the friendly gtsummary outputs.
Thanks in advance.

The trick is to specify the formula= argument here. Example Below!!
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.0'
Data <- tibble::tribble(
~nvx, ~anomalies_tot, ~age_moyen, ~productivite,
1L, 2, "Entre 8 et 10 jours", "Entre 9 500 et 11 000 L/VL",
1L, 1, "Entre 8 et 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 3, "Plus de 10 jours", "Moins de 9 500 L/VL",
1L, 4, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 3, "Plus de 10 jours", "Moins de 9 500 L/VL",
2L, 3, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
2L, 5, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
2L, 1, "Moins de 8 jours", "Plus de 11 000 L/VL",
3L, 2, "Entre 8 et 10 jours", "Moins de 9 500 L/VL",
3L, 8, "Moins de 8 jours", "Moins de 9 500 L/VL",
1L, 3, "Moins de 8 jours", "Entre 9 500 et 11 000 L/VL",
1L, 2, "Entre 8 et 10 jours", "Moins de 9 500 L/VL",
5L, 12, "Moins de 8 jours", "Entre 9 500 et 11 000 L/VL",
1L, 2, "Entre 8 et 10 jours", "Moins de 9 500 L/VL",
3L, 2, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 3, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 5, "Plus de 10 jours", "Entre 9 500 et 11 000 L/VL",
2L, 2, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
3L, 5, "Entre 8 et 10 jours", "Plus de 11 000 L/VL",
11L, 26, "Moins de 8 jours", "Moins de 9 500 L/VL",
3L, 8, "Moins de 8 jours", "Entre 9 500 et 11 000 L/VL",
3L, 7, "Plus de 10 jours", "Plus de 11 000 L/VL",
1L, 0, "Plus de 10 jours", "Moins de 9 500 L/VL"
)
tbl <-
Data %>%
tbl_uvregression(
y = anomalies_tot,
formula = "{y} ~ {x} + offset(log(nvx))",
include = -nvx,
exponentiate = TRUE,
method = glm,
method.args = list(family = poisson(link = log))
)
Created on 2022-06-09 by the reprex package (v2.0.1)

Related

Assign weight and rate to products based on size of variety & weight

I have table1
line
products
product variety
weight
rate
1
a
49
2
b
27
3
c
26
4
d
28
5
e
7
6
f
6
7
g
7
8
h
13
9
i
12
10
j
13
11
k
13
12
l
3
13
m
6
14
n
13
15
o
5
16
p
5
17
q
10
18
r
707
19
s
26
20
t
10
21
u
10
22
v
10
23
w
5
24
x
2
25
y
2
26
z
2
Want to assign weight to each products based on the size of product variety and rate will be calculated based on the weight like, the 1st largest weight = 1, the 2nd largest weight = 2 and so on. The total sum of weights should be 100
The expected result looks like below
line
products
product variety
weight
rate
1
a
49
                 6.38
2
2
b
27
                 5.40
4
3
c
26
                 5.34
5
4
d
28
                 5.46
3
5
e
7
                 3.19
9
6
f
6
                 2.94
10
7
g
7
                 3.19
9
8
h
13
                 4.20
6
9
i
12
                 4.07
7
10
j
13
                 4.20
6
11
k
13
                 4.20
6
12
l
3
                 1.80
12
13
m
6
                 2.94
10
14
n
13
                 4.20
6
15
o
5
                 2.64
11
16
p
5
                 2.64
11
17
q
10
                 3.77
8
18
r
707
               10.75
1
19
s
26
                 5.34
5
20
t
10
                 3.77
8
21
u
10
                 3.77
8
22
v
10
                 3.77
8
23
w
5
                 2.64
11
24
x
2
                 1.14
13
25
y
2
                 1.14
13
26
z
2
                 1.14
13
Tried in excel with the below formulas and is working perfectly, but i want something like this in postgresql to provide same above result.
D2=LOG10(C2)/SUM(LOG10($C$2:$C$27))*100
E2=SUMPRODUCT(($D2 < $D$2:$D$27)/COUNTIF($D$2:$D$27,$D$2:$D$27))+1
Calculate weights in the inner query and use the window function dense_rank():
select
line,
products,
product_variety,
weight,
dense_rank() over (order by weight desc) as rate
from (
select
line,
products,
product_variety,
round(log(product_variety::dec)/ sum* 100, 2) as weight
from table1
cross join lateral (
select sum(log(product_variety::dec))
from table1
) s
) s
order by line
Test the query in db<>fiddle.

Why there is 'expected an element of either String'

import networkx as nx
from bokeh.transform import linear_cmap
from bokeh.io import show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Circle, HoverTool, TapTool, BoxSelectTool
from bokeh.models.graphs import from_networkx
from bokeh.palettes import Spectral6
output_notebook()
G=nx.Graph(G_fb)
plot = figure(x_range=(-1.1, 1.1), y_range=(-1.1, 1.1))
plot.add_tools(HoverTool(tooltips=[("Name", "#name"),
("Club", "#club")]),
TapTool(),
BoxSelectTool())
graph = from_networkx(G, nx.spring_layout, iterations=1000, scale=1, center=(0,0))
graph.node_renderer.data_source.data['name'] = list(G.nodes())
graph.node_renderer.glyph = Circle(size=10)
graph.node_renderer.glyph = Circle(
size=10,
fill_color=linear_cmap(degrees, palette=Spectral6,low=0, high=100, low_color='blue', high_color='red')
plot.renderers.append(graph)
show(plot)
It comes up with an error saying:
expected an element of either String, Dict(Enum('expr', 'field', 'value', 'transform'), Either(String, Instance(Transform), Instance(Expression), Color)) or Color, got {'field': [5, 6, 12, 7, 8, 6, 6, 9, 8, 4, 3, 5, 5, 7, 5, 7, 4, 4, 3, 6, 3, 5, 10, 1, 7, 4, 8, 2, 9, 6, 5, 5, 9, 11, 11, 3, 9, 1, 10, 1, 6, 6, 5, 8, 7, 7, 4, 7, 2, 1, 3, 1, 6, 3, 1, 1, 2, 2, 1, 2, 2, 1], 'transform': LinearColorMapper(id='1194', ...)}
part of G_fb:
11 1
15 1
16 1
41 1
43 1
48 1
18 2
20 2
27 2
28 2
29 2
37 2
42 2
55 2
11 3
43 3
45 3
62 3
9 4
15 4
60 4
52 5
10 6
14 6
57 6
58 6
10 7
14 7
18 7
55 7
57 7
58 7
20 8
28 8
31 8
41 8
55 8
21 9
29 9
38 9
46 9
60 9
14 10
18 10
33 10
42 10
58 10
30 11
43 11
48 11
52 12
34 13
18 14
33 14
42 14
55 14
58 14
17 15
25 15
34 15
35 15
38 15
39 15
41 15
44 15
51 15
53 15
19 16

Intersect between two vectors but should have the same index

I am trying to get the intersection between two vectors but the index in both vectors should be the same. For example:
x = [1 2 3 4 5 6 7 80 9 100 11 12 103 14 150 16 170 18 20 19]
y = [22 1 3 40 5 4 70 8 90 10 110 12 13 140 15 160 17 18 19 20]
the intesection should be [3 5 12 18] only.
My code:
x = [1 2 3 4 5 6 7 80 9 100 11 12 103 14 150 16 170 18 20 19];
y = [22 1 3 40 5 4 70 8 90 10 110 12 13 140 15 160 17 18 19 20];
inter = intersect(x,y);
It's simple with logical indexing:
>> x = [1 2 3 4 5 6 7 80 9 100 11 12 103 14 150 16 170 18 20 19];
>> y = [22 1 3 40 5 4 70 8 90 10 110 12 13 140 15 160 17 18 19 20];
>> x(x==y)
ans =
3 5 12 18
>> x(abs(x-y)<=3) %// or y(abs(x-y)<=3) for the y values instead of the x values
ans =
2 3 5 6 12 18 20 19

To get the Id's between two dates

I have a table
WEEK_ID WEEK_STARTDATE WEEK_YEAR WEEK_MONTH WEEK_CREATEDTS
252 10/26/2008 2008 11 2008-10-07 15:10:00.000
253 11/02/2008 2008 11 2008-10-07 15:10:00.000
254 11/09/2008 2008 11 2008-10-07 15:10:00.000
255 11/16/2008 2008 11 2008-10-07 15:10:00.000
256 11/23/2008 2008 12 2008-10-07 15:10:00.000
257 11/30/2008 2008 12 2008-10-07 15:10:00.000
258 12/07/2008 2008 12 2008-10-07 15:10:00.000
259 12/14/2008 2008 12 2008-10-07 15:10:00.000
260 12/21/2008 2008 12 2008-10-07 15:10:00.000
266 2/1/2009 2009 2 2008-10-07 15:16:00.000
267 02/08/2009 2009 2 2008-10-07 15:16:00.000
268 02/15/2009 2009 2 2008-10-07 15:16:00.000
269 02/22/2009 2009 2 2008-10-07 15:16:00.000
270 3/1/2009 2009 3 2008-10-07 15:17:00.000
271 03/08/2009 2009 3 2008-10-07 15:17:00.000
272 03/15/2009 2009 3 2008-10-07 15:17:00.000
273 03/22/2009 2009 3 2008-10-07 15:17:00.000
274 3/29/2009 2009 4 2008-10-07 15:19:00.000
275 04/05/2009 2009 4 2008-10-07 15:19:00.000
276 04/12/2009 2009 4 2008-10-07 15:19:00.000
277 04/19/2009 2009 4 2008-10-07 15:19:00.000
278 04/26/2009 2009 4 2008-10-07 15:19:00.000
279 5/3/2009 2009 5 2008-10-07 15:20:00.000
280 05/10/2009 2009 5 2008-10-07 15:20:00.000
281 05/17/2009 2009 5 2008-10-07 15:20:00.000
282 05/24/2009 2009 5 2008-10-07 15:20:00.000
283 5/31/2009 2009 6 2008-10-07 15:34:00.000
284 06/07/2009 2009 6 2008-10-07 15:34:00.000
285 06/14/2009 2009 6 2008-10-07 15:34:00.000
286 06/21/2009 2009 6 2008-10-07 15:34:00.000
287 6/28/2009 2009 7 2008-10-07 15:36:00.000
288 07/05/2009 2009 7 2008-10-07 15:36:00.000
289 07/12/2009 2009 7 2008-10-07 15:36:00.000
290 07/19/2009 2009 7 2008-10-07 15:36:00.000
291 07/26/2009 2009 7 2008-10-07 15:36:00.000
297 12/28/2008 2009 1 2008-10-08 03:45:00.000
298 01/04/2009 2009 1 2008-10-08 03:45:00.000
299 01/11/2009 2009 1 2008-10-08 03:45:00.000
300 01/18/2009 2009 1 2008-10-08 03:45:00.000
301 01/25/2009 2009 1 2008-10-08 03:45:00.000
302 8/2/2009 2009 8 2008-10-28 12:52:00.000
303 08/09/2009 2009 8 2008-10-28 12:52:00.000
304 08/16/2009 2009 8 2008-10-28 12:52:00.000
305 08/23/2009 2009 8 2008-10-28 12:52:00.000
306 8/30/2009 2009 9 2008-10-28 12:54:00.000
307 09/06/2009 2009 9 2008-10-28 12:54:00.000
308 09/13/2009 2009 9 2008-10-28 12:54:00.000
309 09/20/2009 2009 9 2008-10-28 12:54:00.000
310 9/27/2009 2009 10 2008-10-28 12:54:00.000
311 10/04/2009 2009 10 2008-10-28 12:54:00.000
312 10/11/2009 2009 10 2008-10-28 12:54:00.000
313 10/18/2009 2009 10 2008-10-28 12:54:00.000
314 10/25/2009 2009 10 2008-10-28 12:54:00.000
315 11/1/2009 2009 11 2008-10-28 12:55:00.000
316 11/08/2009 2009 11 2008-10-28 12:55:00.000
317 11/15/2009 2009 11 2008-10-28 12:55:00.000
318 11/22/2009 2009 11 2008-10-28 12:55:00.000
319 11/29/2009 2009 12 2008-10-28 12:55:00.000
320 12/06/2009 2009 12 2008-10-28 12:55:00.000
321 12/13/2009 2009 12 2008-10-28 12:55:00.000
322 12/20/2009 2009 12 2008-10-28 12:55:00.000
323 12/28/2009 2010 1 2008-10-28 12:56:00.000
324 01/04/2010 2010 1 2008-10-28 12:56:00.000
325 01/11/2010 2010 1 2008-10-28 12:56:00.000
326 01/18/2010 2010 1 2008-10-28 12:56:00.000
327 01/25/2010 2010 1 2008-10-28 12:56:00.000
329 02/01/2010 2010 2 2010-01-18 08:10:00.000
330 02/08/2010 2010 2 2010-01-18 08:10:00.000
331 02/15/2010 2010 2 2010-01-18 08:10:00.000
332 02/22/2010 2010 2 2010-01-18 08:10:00.000
333 03/01/2010 2010 3 2010-01-18 08:11:00.000
334 03/08/2010 2010 3 2010-01-18 08:11:00.000
335 03/15/2010 2010 3 2010-01-18 08:11:00.000
336 03/22/2010 2010 3 2010-01-18 08:11:00.000
337 03/29/2010 2010 4 2010-03-17 11:00:00.000
338 04/05/2010 2010 4 2010-03-17 11:00:00.000
339 04/12/2010 2010 4 2010-03-17 11:00:00.000
340 04/19/2010 2010 4 2010-03-17 11:00:00.000
341 04/26/2010 2010 4 2010-03-17 11:00:00.000
342 05/03/2010 2010 5 2010-03-17 11:01:00.000
343 05/10/2010 2010 5 2010-03-17 11:01:00.000
344 05/17/2010 2010 5 2010-03-17 11:01:00.000
345 05/24/2010 2010 5 2010-03-17 11:01:00.000
346 05/31/2010 2010 6 2010-03-17 11:03:00.000
347 06/07/2010 2010 6 2010-03-17 11:03:00.000
348 06/14/2010 2010 6 2010-03-17 11:03:00.000
349 06/21/2010 2010 6 2010-03-17 11:03:00.000
350 06/28/2010 2010 7 2010-03-17 11:03:00.000
351 07/05/2010 2010 7 2010-03-17 11:03:00.000
352 07/12/2010 2010 7 2010-03-17 11:03:00.000
353 07/19/2010 2010 7 2010-03-17 11:03:00.000
354 07/26/2010 2010 7 2010-03-17 11:03:00.000
355 08/02/2010 2010 8 2010-03-17 11:04:00.000
356 08/09/2010 2010 8 2010-03-17 11:04:00.000
357 08/16/2010 2010 8 2010-03-17 11:04:00.000
358 08/23/2010 2010 8 2010-03-17 11:04:00.000
359 08/30/2010 2010 9 2010-03-17 11:05:00.000
360 09/06/2010 2010 9 2010-03-17 11:05:00.000
361 09/13/2010 2010 9 2010-03-17 11:05:00.000
362 09/20/2010 2010 9 2010-03-17 11:05:00.000
363 09/27/2010 2010 10 2010-03-17 11:06:00.000
364 10/04/2010 2010 10 2010-03-17 11:06:00.000
365 10/11/2010 2010 10 2010-03-17 11:06:00.000
366 10/18/2010 2010 10 2010-03-17 11:06:00.000
367 10/25/2010 2010 10 2010-03-17 11:06:00.000
368 11/01/2010 2010 11 2010-03-17 11:09:00.000
369 11/08/2010 2010 11 2010-03-17 11:09:00.000
370 11/15/2010 2010 11 2010-03-17 11:09:00.000
371 11/22/2010 2010 11 2010-03-17 11:09:00.000
372 11/29/2010 2010 12 2010-03-17 11:10:00.000
373 12/06/2010 2010 12 2010-03-17 11:10:00.000
374 12/13/2010 2010 12 2010-03-17 11:10:00.000
375 12/20/2010 2010 12 2010-03-17 11:10:00.000
376 12/27/2010 2011 1 2010-03-17 11:11:00.000
377 01/03/2011 2011 1 2010-03-17 11:11:00.000
378 01/10/2011 2011 1 2010-03-17 11:11:00.000
379 01/17/2011 2011 1 2010-03-17 11:11:00.000
380 01/24/2011 2011 1 2010-03-17 11:11:00.000
381 01/31/2011 2011 2 NULL
382 02/07/2011 2011 2 NULL
383 02/14/2011 2011 2 NULL
384 02/21/2011 2011 2 NULL
441 02/28/2011 2011 3 NULL
442 03/07/2011 2011 3 NULL
443 03/14/2011 2011 3 NULL
444 03/21/2011 2011 3 NULL
451 03/28/2011 2011 4 NULL
452 04/04/2011 2011 4 NULL
453 04/11/2011 2011 4 NULL
454 04/18/2011 2011 4 NULL
455 04/25/2011 2011 4 NULL
456 05/02/2011 2011 5 NULL
457 05/09/2011 2011 5 NULL
458 05/16/2011 2011 5 NULL
459 05/23/2011 2011 5 NULL
460 05/30/2011 2011 6 NULL
461 06/06/2011 2011 6 NULL
462 06/13/2011 2011 6 NULL
463 06/20/2011 2011 6 NULL
464 06/27/2011 2011 7 NULL
465 07/04/2011 2011 7 NULL
466 07/11/2011 2011 7 NULL
467 07/18/2011 2011 7 NULL
468 07/25/2011 2011 7 NULL
469 08/01/2011 2011 8 NULL
470 08/08/2011 2011 8 NULL
471 08/15/2011 2011 8 NULL
472 08/22/2011 2011 8 NULL
473 08/29/2011 2011 9 NULL
474 09/05/2011 2011 9 NULL
475 09/12/2011 2011 9 NULL
476 09/19/2011 2011 9 NULL
477 09/26/2011 2011 10 NULL
478 10/03/2011 2011 10 NULL
479 10/10/2011 2011 10 NULL
480 10/17/2011 2011 10 NULL
481 10/24/2011 2011 10 NULL
482 10/31/2011 2011 11 NULL
483 11/07/2011 2011 11 NULL
484 11/14/2011 2011 11 NULL
485 11/21/2011 2011 11 NULL
486 11/28/2011 2011 12 NULL
487 12/05/2011 2011 12 NULL
488 12/12/2011 2011 12 NULL
489 12/19/2011 2011 12 NULL
491 12/26/2011 2012 1 NULL
492 01/02/2012 2012 1 NULL
493 01/09/2012 2012 1 NULL
494 01/16/2012 2012 1 NULL
495 01/23/2012 2012 1 NULL
496 01/30/2012 2012 2 NULL
497 02/06/2012 2012 2 NULL
498 02/13/2012 2012 2 NULL
499 02/20/2012 2012 2 NULL
500 02/27/2012 2012 3 NULL
501 03/05/2012 2012 3 NULL
502 03/12/2012 2012 3 NULL
503 03/19/2012 2012 3 NULL
504 03/26/2012 2012 4 NULL
505 04/02/2012 2012 4 NULL
506 04/09/2012 2012 4 NULL
507 04/16/2012 2012 4 NULL
508 04/23/2012 2012 4 NULL
509 04/30/2012 2012 5 NULL
510 05/07/2012 2012 5 NULL
511 05/14/2012 2012 5 NULL
512 05/21/2012 2012 5 NULL
513 05/28/2012 2012 6 NULL
514 06/04/2012 2012 6 NULL
515 06/11/2012 2012 6 NULL
516 06/18/2012 2012 6 NULL
517 06/25/2012 2012 7 NULL
518 07/02/2012 2012 7 NULL
519 07/09/2012 2012 7 NULL
520 07/16/2012 2012 7 NULL
521 07/23/2012 2012 7 NULL
522 07/30/2012 2012 8 NULL
523 08/06/2012 2012 8 NULL
524 08/13/2012 2012 8 NULL
525 08/20/2012 2012 8 NULL
526 08/27/2012 2012 9 NULL
527 09/03/2012 2012 9 NULL
528 09/10/2012 2012 9 NULL
529 09/17/2012 2012 9 NULL
530 09/24/2012 2012 10 NULL
531 10/01/2012 2012 10 NULL
532 10/08/2012 2012 10 NULL
533 10/15/2012 2012 10 NULL
534 10/22/2012 2012 10 NULL
535 10/29/2012 2012 11 NULL
536 11/05/2012 2012 11 NULL
537 11/12/2012 2012 11 NULL
538 11/19/2012 2012 11 NULL
539 11/26/2012 2012 12 NULL
540 12/03/2012 2012 12 NULL
541 12/10/2012 2012 12 NULL
542 12/17/2012 2012 12 NULL
543 12/24/2012 2013 1 NULL
544 12/31/2012 2013 1 NULL
545 01/07/2013 2013 1 NULL
546 01/14/2013 2013 1 NULL
547 01/21/2013 2013 1 NULL
548 01/28/2012 2013 1 NULL
and I create a query by adding 7 days to week_startdate
select
week_id, week_startdate,
convert(varchar, dateadd(day, 7, week_startdate), 101) as week_enddate
from dbo.TBL_S3_FISCALWEEKS_1
and output of the above query is
week_id week_startdate week_enddate
252 10/26/2008 11/02/2008
253 11/02/2008 11/09/2008
254 11/09/2008 11/16/2008
255 11/16/2008 11/23/2008
256 11/23/2008 11/30/2008
257 11/30/2008 12/07/2008
258 12/07/2008 12/14/2008
259 12/14/2008 12/21/2008
260 12/21/2008 12/28/2008
266 2/1/2009 02/08/2009
267 02/08/2009 02/15/2009
268 02/15/2009 02/22/2009
269 02/22/2009 03/01/2009
270 3/1/2009 03/08/2009
271 03/08/2009 03/15/2009
272 03/15/2009 03/22/2009
273 03/22/2009 03/29/2009
274 3/29/2009 04/05/2009
275 04/05/2009 04/12/2009
276 04/12/2009 04/19/2009
277 04/19/2009 04/26/2009
278 04/26/2009 05/03/2009
279 5/3/2009 05/10/2009
280 05/10/2009 05/17/2009
281 05/17/2009 05/24/2009
282 05/24/2009 05/31/2009
283 5/31/2009 06/07/2009
284 06/07/2009 06/14/2009
285 06/14/2009 06/21/2009
286 06/21/2009 06/28/2009
287 6/28/2009 07/05/2009
288 07/05/2009 07/12/2009
289 07/12/2009 07/19/2009
290 07/19/2009 07/26/2009
291 07/26/2009 08/02/2009
297 12/28/2008 01/04/2009
298 01/04/2009 01/11/2009
299 01/11/2009 01/18/2009
300 01/18/2009 01/25/2009
301 01/25/2009 02/01/2009
302 8/2/2009 08/09/2009
303 08/09/2009 08/16/2009
304 08/16/2009 08/23/2009
305 08/23/2009 08/30/2009
306 8/30/2009 09/06/2009
307 09/06/2009 09/13/2009
308 09/13/2009 09/20/2009
309 09/20/2009 09/27/2009
310 9/27/2009 10/04/2009
311 10/04/2009 10/11/2009
312 10/11/2009 10/18/2009
313 10/18/2009 10/25/2009
314 10/25/2009 11/01/2009
315 11/1/2009 11/08/2009
316 11/08/2009 11/15/2009
317 11/15/2009 11/22/2009
318 11/22/2009 11/29/2009
319 11/29/2009 12/06/2009
320 12/06/2009 12/13/2009
321 12/13/2009 12/20/2009
322 12/20/2009 12/27/2009
323 12/28/2009 01/04/2010
324 01/04/2010 01/11/2010
325 01/11/2010 01/18/2010
326 01/18/2010 01/25/2010
327 01/25/2010 02/01/2010
329 02/01/2010 02/08/2010
330 02/08/2010 02/15/2010
331 02/15/2010 02/22/2010
332 02/22/2010 03/01/2010
333 03/01/2010 03/08/2010
334 03/08/2010 03/15/2010
335 03/15/2010 03/22/2010
336 03/22/2010 03/29/2010
337 03/29/2010 04/05/2010
338 04/05/2010 04/12/2010
339 04/12/2010 04/19/2010
340 04/19/2010 04/26/2010
341 04/26/2010 05/03/2010
342 05/03/2010 05/10/2010
343 05/10/2010 05/17/2010
344 05/17/2010 05/24/2010
345 05/24/2010 05/31/2010
346 05/31/2010 06/07/2010
347 06/07/2010 06/14/2010
348 06/14/2010 06/21/2010
349 06/21/2010 06/28/2010
350 06/28/2010 07/05/2010
351 07/05/2010 07/12/2010
352 07/12/2010 07/19/2010
353 07/19/2010 07/26/2010
354 07/26/2010 08/02/2010
355 08/02/2010 08/09/2010
356 08/09/2010 08/16/2010
357 08/16/2010 08/23/2010
358 08/23/2010 08/30/2010
359 08/30/2010 09/06/2010
360 09/06/2010 09/13/2010
361 09/13/2010 09/20/2010
362 09/20/2010 09/27/2010
363 09/27/2010 10/04/2010
364 10/04/2010 10/11/2010
365 10/11/2010 10/18/2010
366 10/18/2010 10/25/2010
367 10/25/2010 11/01/2010
368 11/01/2010 11/08/2010
369 11/08/2010 11/15/2010
370 11/15/2010 11/22/2010
371 11/22/2010 11/29/2010
372 11/29/2010 12/06/2010
373 12/06/2010 12/13/2010
374 12/13/2010 12/20/2010
375 12/20/2010 12/27/2010
376 12/27/2010 01/03/2011
377 01/03/2011 01/10/2011
378 01/10/2011 01/17/2011
379 01/17/2011 01/24/2011
380 01/24/2011 01/31/2011
381 01/31/2011 02/07/2011
382 02/07/2011 02/14/2011
383 02/14/2011 02/21/2011
384 02/21/2011 02/28/2011
441 02/28/2011 03/07/2011
442 03/07/2011 03/14/2011
443 03/14/2011 03/21/2011
444 03/21/2011 03/28/2011
451 03/28/2011 04/04/2011
452 04/04/2011 04/11/2011
453 04/11/2011 04/18/2011
454 04/18/2011 04/25/2011
455 04/25/2011 05/02/2011
456 05/02/2011 05/09/2011
457 05/09/2011 05/16/2011
458 05/16/2011 05/23/2011
459 05/23/2011 05/30/2011
460 05/30/2011 06/06/2011
461 06/06/2011 06/13/2011
462 06/13/2011 06/20/2011
463 06/20/2011 06/27/2011
464 06/27/2011 07/04/2011
465 07/04/2011 07/11/2011
466 07/11/2011 07/18/2011
467 07/18/2011 07/25/2011
468 07/25/2011 08/01/2011
469 08/01/2011 08/08/2011
470 08/08/2011 08/15/2011
471 08/15/2011 08/22/2011
472 08/22/2011 08/29/2011
473 08/29/2011 09/05/2011
474 09/05/2011 09/12/2011
475 09/12/2011 09/19/2011
476 09/19/2011 09/26/2011
477 09/26/2011 10/03/2011
478 10/03/2011 10/10/2011
479 10/10/2011 10/17/2011
480 10/17/2011 10/24/2011
481 10/24/2011 10/31/2011
482 10/31/2011 11/07/2011
483 11/07/2011 11/14/2011
484 11/14/2011 11/21/2011
485 11/21/2011 11/28/2011
486 11/28/2011 12/05/2011
487 12/05/2011 12/12/2011
488 12/12/2011 12/19/2011
489 12/19/2011 12/26/2011
491 12/26/2011 01/02/2012
492 01/02/2012 01/09/2012
493 01/09/2012 01/16/2012
494 01/16/2012 01/23/2012
495 01/23/2012 01/30/2012
496 01/30/2012 02/06/2012
497 02/06/2012 02/13/2012
498 02/13/2012 02/20/2012
499 02/20/2012 02/27/2012
500 02/27/2012 03/05/2012
501 03/05/2012 03/12/2012
502 03/12/2012 03/19/2012
503 03/19/2012 03/26/2012
504 03/26/2012 04/02/2012
505 04/02/2012 04/09/2012
506 04/09/2012 04/16/2012
507 04/16/2012 04/23/2012
508 04/23/2012 04/30/2012
509 04/30/2012 05/07/2012
510 05/07/2012 05/14/2012
511 05/14/2012 05/21/2012
512 05/21/2012 05/28/2012
513 05/28/2012 06/04/2012
514 06/04/2012 06/11/2012
515 06/11/2012 06/18/2012
516 06/18/2012 06/25/2012
517 06/25/2012 07/02/2012
518 07/02/2012 07/09/2012
519 07/09/2012 07/16/2012
520 07/16/2012 07/23/2012
521 07/23/2012 07/30/2012
522 07/30/2012 08/06/2012
523 08/06/2012 08/13/2012
524 08/13/2012 08/20/2012
525 08/20/2012 08/27/2012
526 08/27/2012 09/03/2012
527 09/03/2012 09/10/2012
528 09/10/2012 09/17/2012
529 09/17/2012 09/24/2012
530 09/24/2012 10/01/2012
531 10/01/2012 10/08/2012
532 10/08/2012 10/15/2012
533 10/15/2012 10/22/2012
534 10/22/2012 10/29/2012
535 10/29/2012 11/05/2012
536 11/05/2012 11/12/2012
537 11/12/2012 11/19/2012
538 11/19/2012 11/26/2012
539 11/26/2012 12/03/2012
540 12/03/2012 12/10/2012
541 12/10/2012 12/17/2012
542 12/17/2012 12/24/2012
543 12/24/2012 12/31/2012
544 12/31/2012 01/07/2013
545 01/07/2013 01/14/2013
546 01/14/2013 01/21/2013
547 01/21/2013 01/28/2013
548 01/28/2012 02/04/2012
The thing is I need to get week_ids between two days. I need it in function
or procedure would u please help me out as soon as possible
A simple SELECT WHERE BETWEEN should do the job for you. Pass in the two dates as parameters, and
SELECT week_id FROM TBL_S3_FISCALWEEKS_1
WHERE WeekStartDate BETWEEN #DateParam1 AND #DateParam2
This will work even if the exact date doesn't appear in WeekStartDate
So you want a query or function that returns the week_id if you feed it a date (even if it is a date that falls between your week_startdate and week_enddate), right?
You might want to try something like the following query:
SELECT week_id
FROM weeks
WHERE DATEDIFF(dd, week_startdate, input_date) < 7
AND DATEDIFF(dd, week_startdate, input_date) > 0
Check the MSDN DATEDIFF reference for more information on DATEDIFF.

To get Id between two dates in sql server 2008

Help me,
i have a table like this
WEEK_ID WEEK_STARTDATE WEEK_YEAR WEEK_MONTH WEEK_CREATEDTS
------------------------------------------------------------------------
252 10/26/2008 2008 11 2008-10-07 15:10:00.000
253 11/02/2008 2008 11 2008-10-07 15:10:00.000
254 11/09/2008 2008 11 2008-10-07 15:10:00.000
255 11/16/2008 2008 11 2008-10-07 15:10:00.000
256 11/23/2008 2008 12 2008-10-07 15:10:00.000
257 11/30/2008 2008 12 2008-10-07 15:10:00.000
258 12/07/2008 2008 12 2008-10-07 15:10:00.000
259 12/14/2008 2008 12 2008-10-07 15:10:00.000
260 12/21/2008 2008 12 2008-10-07 15:10:00.000
266 2/1/2009 2009 2 2008-10-07 15:16:00.000
267 02/08/2009 2009 2 2008-10-07 15:16:00.000
268 02/15/2009 2009 2 2008-10-07 15:16:00.000
269 02/22/2009 2009 2 2008-10-07 15:16:00.000
270 3/1/2009 2009 3 2008-10-07 15:17:00.000
271 03/08/2009 2009 3 2008-10-07 15:17:00.000
272 03/15/2009 2009 3 2008-10-07 15:17:00.000
273 03/22/2009 2009 3 2008-10-07 15:17:00.000
274 3/29/2009 2009 4 2008-10-07 15:19:00.000
275 04/05/2009 2009 4 2008-10-07 15:19:00.000
276 04/12/2009 2009 4 2008-10-07 15:19:00.000
277 04/19/2009 2009 4 2008-10-07 15:19:00.000
278 04/26/2009 2009 4 2008-10-07 15:19:00.000
279 5/3/2009 2009 5 2008-10-07 15:20:00.000
280 05/10/2009 2009 5 2008-10-07 15:20:00.000
281 05/17/2009 2009 5 2008-10-07 15:20:00.000
282 05/24/2009 2009 5 2008-10-07 15:20:00.000
283 5/31/2009 2009 6 2008-10-07 15:34:00.000
284 06/07/2009 2009 6 2008-10-07 15:34:00.000
285 06/14/2009 2009 6 2008-10-07 15:34:00.000
286 06/21/2009 2009 6 2008-10-07 15:34:00.000
287 6/28/2009 2009 7 2008-10-07 15:36:00.000
288 07/05/2009 2009 7 2008-10-07 15:36:00.000
289 07/12/2009 2009 7 2008-10-07 15:36:00.000
290 07/19/2009 2009 7 2008-10-07 15:36:00.000
291 07/26/2009 2009 7 2008-10-07 15:36:00.000
297 12/28/2008 2009 1 2008-10-08 03:45:00.000
298 01/04/2009 2009 1 2008-10-08 03:45:00.000
299 01/11/2009 2009 1 2008-10-08 03:45:00.000
300 01/18/2009 2009 1 2008-10-08 03:45:00.000
301 01/25/2009 2009 1 2008-10-08 03:45:00.000
302 8/2/2009 2009 8 2008-10-28 12:52:00.000
303 08/09/2009 2009 8 2008-10-28 12:52:00.000
304 08/16/2009 2009 8 2008-10-28 12:52:00.000
305 08/23/2009 2009 8 2008-10-28 12:52:00.000
306 8/30/2009 2009 9 2008-10-28 12:54:00.000
307 09/06/2009 2009 9 2008-10-28 12:54:00.000
308 09/13/2009 2009 9 2008-10-28 12:54:00.000
309 09/20/2009 2009 9 2008-10-28 12:54:00.000
310 9/27/2009 2009 10 2008-10-28 12:54:00.000
311 10/04/2009 2009 10 2008-10-28 12:54:00.000
312 10/11/2009 2009 10 2008-10-28 12:54:00.000
313 10/18/2009 2009 10 2008-10-28 12:54:00.000
314 10/25/2009 2009 10 2008-10-28 12:54:00.000
315 11/1/2009 2009 11 2008-10-28 12:55:00.000
316 11/08/2009 2009 11 2008-10-28 12:55:00.000
317 11/15/2009 2009 11 2008-10-28 12:55:00.000
318 11/22/2009 2009 11 2008-10-28 12:55:00.000
319 11/29/2009 2009 12 2008-10-28 12:55:00.000
320 12/06/2009 2009 12 2008-10-28 12:55:00.000
321 12/13/2009 2009 12 2008-10-28 12:55:00.000
322 12/20/2009 2009 12 2008-10-28 12:55:00.000
323 12/28/2009 2010 1 2008-10-28 12:56:00.000
324 01/04/2010 2010 1 2008-10-28 12:56:00.000
325 01/11/2010 2010 1 2008-10-28 12:56:00.000
326 01/18/2010 2010 1 2008-10-28 12:56:00.000
327 01/25/2010 2010 1 2008-10-28 12:56:00.000
329 02/01/2010 2010 2 2010-01-18 08:10:00.000
330 02/08/2010 2010 2 2010-01-18 08:10:00.000
331 02/15/2010 2010 2 2010-01-18 08:10:00.000
332 02/22/2010 2010 2 2010-01-18 08:10:00.000
333 03/01/2010 2010 3 2010-01-18 08:11:00.000
334 03/08/2010 2010 3 2010-01-18 08:11:00.000
335 03/15/2010 2010 3 2010-01-18 08:11:00.000
336 03/22/2010 2010 3 2010-01-18 08:11:00.000
337 03/29/2010 2010 4 2010-03-17 11:00:00.000
338 04/05/2010 2010 4 2010-03-17 11:00:00.000
339 04/12/2010 2010 4 2010-03-17 11:00:00.000
340 04/19/2010 2010 4 2010-03-17 11:00:00.000
341 04/26/2010 2010 4 2010-03-17 11:00:00.000
342 05/03/2010 2010 5 2010-03-17 11:01:00.000
343 05/10/2010 2010 5 2010-03-17 11:01:00.000
344 05/17/2010 2010 5 2010-03-17 11:01:00.000
345 05/24/2010 2010 5 2010-03-17 11:01:00.000
346 05/31/2010 2010 6 2010-03-17 11:03:00.000
347 06/07/2010 2010 6 2010-03-17 11:03:00.000
348 06/14/2010 2010 6 2010-03-17 11:03:00.000
349 06/21/2010 2010 6 2010-03-17 11:03:00.000
350 06/28/2010 2010 7 2010-03-17 11:03:00.000
351 07/05/2010 2010 7 2010-03-17 11:03:00.000
352 07/12/2010 2010 7 2010-03-17 11:03:00.000
353 07/19/2010 2010 7 2010-03-17 11:03:00.000
354 07/26/2010 2010 7 2010-03-17 11:03:00.000
355 08/02/2010 2010 8 2010-03-17 11:04:00.000
356 08/09/2010 2010 8 2010-03-17 11:04:00.000
357 08/16/2010 2010 8 2010-03-17 11:04:00.000
358 08/23/2010 2010 8 2010-03-17 11:04:00.000
359 08/30/2010 2010 9 2010-03-17 11:05:00.000
360 09/06/2010 2010 9 2010-03-17 11:05:00.000
361 09/13/2010 2010 9 2010-03-17 11:05:00.000
362 09/20/2010 2010 9 2010-03-17 11:05:00.000
363 09/27/2010 2010 10 2010-03-17 11:06:00.000
364 10/04/2010 2010 10 2010-03-17 11:06:00.000
365 10/11/2010 2010 10 2010-03-17 11:06:00.000
366 10/18/2010 2010 10 2010-03-17 11:06:00.000
367 10/25/2010 2010 10 2010-03-17 11:06:00.000
368 11/01/2010 2010 11 2010-03-17 11:09:00.000
369 11/08/2010 2010 11 2010-03-17 11:09:00.000
370 11/15/2010 2010 11 2010-03-17 11:09:00.000
371 11/22/2010 2010 11 2010-03-17 11:09:00.000
372 11/29/2010 2010 12 2010-03-17 11:10:00.000
373 12/06/2010 2010 12 2010-03-17 11:10:00.000
374 12/13/2010 2010 12 2010-03-17 11:10:00.000
375 12/20/2010 2010 12 2010-03-17 11:10:00.000
376 12/27/2010 2011 1 2010-03-17 11:11:00.000
377 01/03/2011 2011 1 2010-03-17 11:11:00.000
378 01/10/2011 2011 1 2010-03-17 11:11:00.000
379 01/17/2011 2011 1 2010-03-17 11:11:00.000
380 01/24/2011 2011 1 2010-03-17 11:11:00.000
381 01/31/2011 2011 2 NULL
382 02/07/2011 2011 2 NULL
383 02/14/2011 2011 2 NULL
384 02/21/2011 2011 2 NULL
441 02/28/2011 2011 3 NULL
442 03/07/2011 2011 3 NULL
443 03/14/2011 2011 3 NULL
444 03/21/2011 2011 3 NULL
451 03/28/2011 2011 4 NULL
452 04/04/2011 2011 4 NULL
453 04/11/2011 2011 4 NULL
454 04/18/2011 2011 4 NULL
455 04/25/2011 2011 4 NULL
456 05/02/2011 2011 5 NULL
457 05/09/2011 2011 5 NULL
458 05/16/2011 2011 5 NULL
459 05/23/2011 2011 5 NULL
460 05/30/2011 2011 6 NULL
461 06/06/2011 2011 6 NULL
462 06/13/2011 2011 6 NULL
463 06/20/2011 2011 6 NULL
464 06/27/2011 2011 7 NULL
465 07/04/2011 2011 7 NULL
466 07/11/2011 2011 7 NULL
467 07/18/2011 2011 7 NULL
468 07/25/2011 2011 7 NULL
469 08/01/2011 2011 8 NULL
470 08/08/2011 2011 8 NULL
471 08/15/2011 2011 8 NULL
472 08/22/2011 2011 8 NULL
473 08/29/2011 2011 9 NULL
474 09/05/2011 2011 9 NULL
475 09/12/2011 2011 9 NULL
476 09/19/2011 2011 9 NULL
477 09/26/2011 2011 10 NULL
478 10/03/2011 2011 10 NULL
479 10/10/2011 2011 10 NULL
480 10/17/2011 2011 10 NULL
481 10/24/2011 2011 10 NULL
482 10/31/2011 2011 11 NULL
483 11/07/2011 2011 11 NULL
484 11/14/2011 2011 11 NULL
485 11/21/2011 2011 11 NULL
486 11/28/2011 2011 12 NULL
487 12/05/2011 2011 12 NULL
488 12/12/2011 2011 12 NULL
489 12/19/2011 2011 12 NULL
491 12/26/2011 2012 1 NULL
492 01/02/2012 2012 1 NULL
493 01/09/2012 2012 1 NULL
494 01/16/2012 2012 1 NULL
495 01/23/2012 2012 1 NULL
496 01/30/2012 2012 2 NULL
497 02/06/2012 2012 2 NULL
498 02/13/2012 2012 2 NULL
499 02/20/2012 2012 2 NULL
500 02/27/2012 2012 3 NULL
501 03/05/2012 2012 3 NULL
502 03/12/2012 2012 3 NULL
503 03/19/2012 2012 3 NULL
504 03/26/2012 2012 4 NULL
505 04/02/2012 2012 4 NULL
506 04/09/2012 2012 4 NULL
507 04/16/2012 2012 4 NULL
508 04/23/2012 2012 4 NULL
509 04/30/2012 2012 5 NULL
510 05/07/2012 2012 5 NULL
511 05/14/2012 2012 5 NULL
512 05/21/2012 2012 5 NULL
513 05/28/2012 2012 6 NULL
514 06/04/2012 2012 6 NULL
515 06/11/2012 2012 6 NULL
516 06/18/2012 2012 6 NULL
517 06/25/2012 2012 7 NULL
518 07/02/2012 2012 7 NULL
519 07/09/2012 2012 7 NULL
520 07/16/2012 2012 7 NULL
521 07/23/2012 2012 7 NULL
522 07/30/2012 2012 8 NULL
523 08/06/2012 2012 8 NULL
524 08/13/2012 2012 8 NULL
525 08/20/2012 2012 8 NULL
526 08/27/2012 2012 9 NULL
527 09/03/2012 2012 9 NULL
528 09/10/2012 2012 9 NULL
529 09/17/2012 2012 9 NULL
530 09/24/2012 2012 10 NULL
531 10/01/2012 2012 10 NULL
532 10/08/2012 2012 10 NULL
533 10/15/2012 2012 10 NULL
534 10/22/2012 2012 10 NULL
535 10/29/2012 2012 11 NULL
536 11/05/2012 2012 11 NULL
537 11/12/2012 2012 11 NULL
538 11/19/2012 2012 11 NULL
539 11/26/2012 2012 12 NULL
540 12/03/2012 2012 12 NULL
541 12/10/2012 2012 12 NULL
542 12/17/2012 2012 12 NULL
543 12/24/2012 2013 1 NULL
544 12/31/2012 2013 1 NULL
545 01/07/2013 2013 1 NULL
546 01/14/2013 2013 1 NULL
547 01/21/2013 2013 1 NULL
548 01/28/2012 2013 1 NULL
I wrote a query to add 6 days to week_startdate like this
select week_id,week_startdate,convert(varchar,dateadd(day,6,week_startdate),101) as week_enddate from dbo.TBL_S3_FISCALWEEKS_1
and the result of the query is
week_id week_startdate week_enddate
252 10/26/2008 11/01/2008
253 11/02/2008 11/08/2008
254 11/09/2008 11/15/2008
255 11/16/2008 11/22/2008
256 11/23/2008 11/29/2008
257 11/30/2008 12/06/2008
258 12/07/2008 12/13/2008
259 12/14/2008 12/20/2008
260 12/21/2008 12/27/2008
266 2/1/2009 02/07/2009
267 02/08/2009 02/14/2009
268 02/15/2009 02/21/2009
269 02/22/2009 02/28/2009
270 3/1/2009 03/07/2009
271 03/08/2009 03/14/2009
272 03/15/2009 03/21/2009
273 03/22/2009 03/28/2009
274 3/29/2009 04/04/2009
275 04/05/2009 04/11/2009
276 04/12/2009 04/18/2009
277 04/19/2009 04/25/2009
278 04/26/2009 05/02/2009
279 5/3/2009 05/09/2009
280 05/10/2009 05/16/2009
281 05/17/2009 05/23/2009
282 05/24/2009 05/30/2009
283 5/31/2009 06/06/2009
284 06/07/2009 06/13/2009
285 06/14/2009 06/20/2009
286 06/21/2009 06/27/2009
287 6/28/2009 07/04/2009
288 07/05/2009 07/11/2009
289 07/12/2009 07/18/2009
290 07/19/2009 07/25/2009
291 07/26/2009 08/01/2009
297 12/28/2008 01/03/2009
298 01/04/2009 01/10/2009
299 01/11/2009 01/17/2009
300 01/18/2009 01/24/2009
301 01/25/2009 01/31/2009
302 8/2/2009 08/08/2009
303 08/09/2009 08/15/2009
304 08/16/2009 08/22/2009
305 08/23/2009 08/29/2009
306 8/30/2009 09/05/2009
307 09/06/2009 09/12/2009
308 09/13/2009 09/19/2009
309 09/20/2009 09/26/2009
310 9/27/2009 10/03/2009
311 10/04/2009 10/10/2009
312 10/11/2009 10/17/2009
313 10/18/2009 10/24/2009
314 10/25/2009 10/31/2009
315 11/1/2009 11/07/2009
316 11/08/2009 11/14/2009
317 11/15/2009 11/21/2009
318 11/22/2009 11/28/2009
319 11/29/2009 12/05/2009
320 12/06/2009 12/12/2009
321 12/13/2009 12/19/2009
322 12/20/2009 12/26/2009
323 12/28/2009 01/03/2010
324 01/04/2010 01/10/2010
325 01/11/2010 01/17/2010
326 01/18/2010 01/24/2010
327 01/25/2010 01/31/2010
329 02/01/2010 02/07/2010
330 02/08/2010 02/14/2010
331 02/15/2010 02/21/2010
332 02/22/2010 02/28/2010
333 03/01/2010 03/07/2010
334 03/08/2010 03/14/2010
335 03/15/2010 03/21/2010
336 03/22/2010 03/28/2010
337 03/29/2010 04/04/2010
338 04/05/2010 04/11/2010
339 04/12/2010 04/18/2010
340 04/19/2010 04/25/2010
341 04/26/2010 05/02/2010
342 05/03/2010 05/09/2010
343 05/10/2010 05/16/2010
344 05/17/2010 05/23/2010
345 05/24/2010 05/30/2010
346 05/31/2010 06/06/2010
347 06/07/2010 06/13/2010
348 06/14/2010 06/20/2010
349 06/21/2010 06/27/2010
350 06/28/2010 07/04/2010
351 07/05/2010 07/11/2010
352 07/12/2010 07/18/2010
353 07/19/2010 07/25/2010
354 07/26/2010 08/01/2010
355 08/02/2010 08/08/2010
356 08/09/2010 08/15/2010
357 08/16/2010 08/22/2010
358 08/23/2010 08/29/2010
359 08/30/2010 09/05/2010
360 09/06/2010 09/12/2010
361 09/13/2010 09/19/2010
362 09/20/2010 09/26/2010
363 09/27/2010 10/03/2010
364 10/04/2010 10/10/2010
365 10/11/2010 10/17/2010
366 10/18/2010 10/24/2010
367 10/25/2010 10/31/2010
368 11/01/2010 11/07/2010
369 11/08/2010 11/14/2010
370 11/15/2010 11/21/2010
371 11/22/2010 11/28/2010
372 11/29/2010 12/05/2010
373 12/06/2010 12/12/2010
374 12/13/2010 12/19/2010
375 12/20/2010 12/26/2010
376 12/27/2010 01/02/2011
377 01/03/2011 01/09/2011
378 01/10/2011 01/16/2011
379 01/17/2011 01/23/2011
380 01/24/2011 01/30/2011
381 01/31/2011 02/06/2011
382 02/07/2011 02/13/2011
383 02/14/2011 02/20/2011
384 02/21/2011 02/27/2011
441 02/28/2011 03/06/2011
442 03/07/2011 03/13/2011
443 03/14/2011 03/20/2011
444 03/21/2011 03/27/2011
451 03/28/2011 04/03/2011
452 04/04/2011 04/10/2011
453 04/11/2011 04/17/2011
454 04/18/2011 04/24/2011
455 04/25/2011 05/01/2011
456 05/02/2011 05/08/2011
457 05/09/2011 05/15/2011
458 05/16/2011 05/22/2011
459 05/23/2011 05/29/2011
460 05/30/2011 06/05/2011
461 06/06/2011 06/12/2011
462 06/13/2011 06/19/2011
463 06/20/2011 06/26/2011
464 06/27/2011 07/03/2011
465 07/04/2011 07/10/2011
466 07/11/2011 07/17/2011
467 07/18/2011 07/24/2011
468 07/25/2011 07/31/2011
469 08/01/2011 08/07/2011
470 08/08/2011 08/14/2011
471 08/15/2011 08/21/2011
472 08/22/2011 08/28/2011
473 08/29/2011 09/04/2011
474 09/05/2011 09/11/2011
475 09/12/2011 09/18/2011
476 09/19/2011 09/25/2011
477 09/26/2011 10/02/2011
478 10/03/2011 10/09/2011
479 10/10/2011 10/16/2011
480 10/17/2011 10/23/2011
481 10/24/2011 10/30/2011
482 10/31/2011 11/06/2011
483 11/07/2011 11/13/2011
484 11/14/2011 11/20/2011
485 11/21/2011 11/27/2011
486 11/28/2011 12/04/2011
487 12/05/2011 12/11/2011
488 12/12/2011 12/18/2011
489 12/19/2011 12/25/2011
491 12/26/2011 01/01/2012
492 01/02/2012 01/08/2012
493 01/09/2012 01/15/2012
494 01/16/2012 01/22/2012
495 01/23/2012 01/29/2012
496 01/30/2012 02/05/2012
497 02/06/2012 02/12/2012
498 02/13/2012 02/19/2012
499 02/20/2012 02/26/2012
500 02/27/2012 03/04/2012
501 03/05/2012 03/11/2012
502 03/12/2012 03/18/2012
503 03/19/2012 03/25/2012
504 03/26/2012 04/01/2012
505 04/02/2012 04/08/2012
506 04/09/2012 04/15/2012
507 04/16/2012 04/22/2012
508 04/23/2012 04/29/2012
509 04/30/2012 05/06/2012
510 05/07/2012 05/13/2012
511 05/14/2012 05/20/2012
512 05/21/2012 05/27/2012
513 05/28/2012 06/03/2012
514 06/04/2012 06/10/2012
515 06/11/2012 06/17/2012
516 06/18/2012 06/24/2012
517 06/25/2012 07/01/2012
518 07/02/2012 07/08/2012
519 07/09/2012 07/15/2012
520 07/16/2012 07/22/2012
521 07/23/2012 07/29/2012
522 07/30/2012 08/05/2012
523 08/06/2012 08/12/2012
524 08/13/2012 08/19/2012
525 08/20/2012 08/26/2012
526 08/27/2012 09/02/2012
527 09/03/2012 09/09/2012
528 09/10/2012 09/16/2012
529 09/17/2012 09/23/2012
530 09/24/2012 09/30/2012
531 10/01/2012 10/07/2012
532 10/08/2012 10/14/2012
533 10/15/2012 10/21/2012
534 10/22/2012 10/28/2012
535 10/29/2012 11/04/2012
536 11/05/2012 11/11/2012
537 11/12/2012 11/18/2012
538 11/19/2012 11/25/2012
539 11/26/2012 12/02/2012
540 12/03/2012 12/09/2012
541 12/10/2012 12/16/2012
542 12/17/2012 12/23/2012
543 12/24/2012 12/30/2012
544 12/31/2012 01/06/2013
545 01/07/2013 01/13/2013
546 01/14/2013 01/20/2013
547 01/21/2013 01/27/2013
548 01/28/2012 02/03/2012
I don't have week_enddate column I created it by adding 6 days to week_startdate.
the requirement is If i pass the date as input parameter between week_startdate and week_enddate I must get week_id
for example if i pass date between 04/02/2012 to 04/08/2012 I should get only that week_id
that is between
04/02/2012,
04/03/2012,
04/04/2012,
04/05/2012,
04/06/2012,
04/07/2012,
04/08/2012
I must get week_id 505 like that.The table dont have week_enddate I created in the select statement by adding 6 days but I should pass only startdate and I should get the week_id between two dates
help me
try the following query
select week_id
from dbo.TBL_S3_FISCALWEEKS_1
where #yourdate between week_startdate and convert(varchar,dateadd(day,6,week_startdate),101)