How To Convert Dw Into Monday, Tuesday, Etc

Nov 3, 2005

I am writing an sql query as follow:SELECT     DATEPART(dw, CALLSTARTTIME) AS dayFROM         TABLEGROUP BY DATEPART(dw, CALLSTARTTIME)ORDER BY DATEPART(dw, CALLSTARTTIME)it returnsday====1234567my question is, how can I return monday, tuesday, wednesday, etc... insteand of 1-7?

View 1 Replies


ADVERTISEMENT

Put All The Day Monday'S Next Month + Add This Last Monday ?

Mar 5, 2008

i have this FUNCTION
and the FUNCTION work OK
now how to add to this FUNCTION another mondy date ?
"last month last monday"



Code Snippet
CREATE FUNCTION [dbo].[Monday_List]( @arg_date datetime )
returns table
as
return
(
select convert(varchar(10), (dateadd(mm, datediff (mm, 0, @arg_date), 0)
+ (8 - datepart(dw, dateadd(mm, datediff (mm, 0,
@arg_date), 0))) % 7) + offset, 103)
as Date,
[Index],
Number
from
( select 1 as Number, 'First_Monday' as [Index], 0 as offset union all
select 2, 'Second_Monday', 7 union all
select 3, 'Third_Monday', 14 union all
select 4, 'Fourth_Monday', 21 union all
select 5, 'Fifth_Monday', 28
) x
where month(dateadd(mm, datediff (mm, 0, @arg_date), 0)
+ (8 - datepart(dw, dateadd(mm, datediff (mm, 0,
@arg_date), 0))) % 7)
= month((dateadd(mm, datediff (mm, 0, @arg_date), 0)
+ (8 - datepart(dw, dateadd(mm, datediff (mm, 0,
@arg_date), 0))) % 7) + offset)
)


this is the Output i get



select * from Monday_List('1/3/8')

Date Index Number
---------- ------------- -----------
03/03/2008 First_Monday 1
10/03/2008 Second_Monday 2
17/03/2008 Third_Monday 3
24/03/2008 Fourth_Monday 4
31/03/2008 Fifth_Monday 5
*/


now i need to add to the FUNCTION "last month last monday"
like this


select * from Monday_List('1/3/8')

Date Index Number
---------- ------------- -----------
04/02/2008 last monday 0 ---------------------- i need to add
03/03/2008 First_Monday 1
10/03/2008 Second_Monday 2
17/03/2008 Third_Monday 3
24/03/2008 Fourth_Monday 4
31/03/2008 Fifth_Monday 5
*/

------------------------------
TNX

View 11 Replies View Related

Finding The 3rd Tuesday Of The Month

May 27, 2008

Hi all -- I'm trying to create a function that can return the date in a particular month on which the 3rd Tuesday falls. (Or the 2nd Thursday, or the 5th Monday, etc.) I know that my weeks always start on Sundays (and end on Saturdays) but I can't seem to figure out how to accomplish this. I've searched these forums and found threads that talk about how to build a calendar-type table but it is not clear, at least to me, how to use such calendar to find the Xth weekday of the month. Any ideas? Thanks,

Bill

View 2 Replies View Related

Get Date Of Tuesday Of Past X Years From Now

Feb 4, 2015

I am trying to get the date of Tuesday from now of the past x Years

The below Query works fine for weeks

DECLARE @x INT
SET x= 53
SELECT CONVERT(VARCHAR, DATEADD(WW,-@x,DATEADD(DD, -((@@DATEFIRST + DATEPART(DW, GETDATE()) -3) % 7), GETDATE())) ,23)

The issue is with below query for any passed Number of Years

SET x = 7
CONVERT(VARCHAR,DATEADD(yy, -@x, DATEADD(D, -((@@DATEFIRST + DATEPART(DW, GETDATE()) -3) % 7), GETDATE())) ,23)

So need to get past years Tuesday Date and also verify if week also works for any passed week numbers ? The x parameter can be changed based on the situation

View 9 Replies View Related

How To Find Second Monday Of October?

Jul 2, 2006

Hi,

Can any one help to get the date of second monday of october for the given year.

Ex: the input will be 10, 2006

and output should be 9, where 9 is the second monday date

View 3 Replies View Related

How To Put All The Day Monday'S Next Month In One Table

Jan 10, 2008

hi need help
how can i put all the monday'S day next month in one table like this
so i can use it all years

date index number
---------------------------------------------------------

04/02/2008 first_monday 1
11/02/2008 second_monday 2
18/02/2007 third_monday 3
25/02/2008 fourth_monday 4



TNX

View 13 Replies View Related

Get Last Monday Through Sunday Data Question

Jan 12, 2007

I'm using VB.Net and SQL Server. Here's the scenario I have that I can't figure out how to accomplish:
(btw, this is all manual - I'm NOT using an ASP.Net Calendar control) I want to provide a week's worth of calendar data automatically. Let's say I have all the calendar dates and times in a table. But - I only want to show the data from the current week.
So, no matter which day the end user loads the page (Monday, Tuesday, Saturday, etc), I want to be able to find the previous Sunday (or Monday?), and then provide data from the table for events that are happening from that Monday, through the next Sunday.
Finding the last Monday (or Sunday?) is the first problem, and then getting only data between that date and the following Sunday is the second problem - how to create the code and hw to create the sql statement - -
any ideas?

View 8 Replies View Related

T-Sql - Calculate Each Monday For A Given Time Period. Help??!!

Jul 20, 2005

I am using SQL Server 2000. I need to query my database for all thecontracts that came in during a certain time frame (user is promptedfor reportingperiodid).Table - PeriodsFields - Reporting Period id intReporting Period desc varchar(30)Reporting Period Begin Date datetimeReporting Period End Date datetimeIf the user selects a 3 then the begin date is Jan. 1, 2004 and theend date is June 30, 2004.Now I need to calculate did any money come in for each week in thattime frame. I need to create a weekly list of all the weeks in thattime frame. Each time frame begins on a Monday. So my list wouldlook like1/5/20041/12/20041/19/20041/26/2004All the way to the end of that time period.How do I create this weekly list from a given time period using T-SQL?I would appreciate any and all help on this.Thanks,Tony

View 3 Replies View Related

Last Monday Date As Default Parameter Value

Dec 3, 2007



I have a stored procedure that grabs the Region key from the user, and the date. But i want to set up 5 reports, for day of the week. So i want to make the second parameter a defualt parameter set by me in each report. which is better then having to create 5 stored procedures with the same info just different dates.
when i try to enter the same data i have in my stored procedure to get Mondays date, i get an error.

Here is what i entered in the report parameter default expression box for the date :


=DATEADD(dd, - 6, DATEADD(dd, 1 - DATEPART(w, GETDATE()), CONVERT(varchar, GETDATE(),

101))))


but i keep getting an error that says:


The Value expression for the report parameter €˜Daily_activity_statistics_datetime€™ contains an error: [BC30451] Name 'dd' is not declared.

Build complete -- 1 errors, 0 warnings



whats wrong with it? This works fine in the stored procedure for the where clause. Please help! this would save me alot of time.

View 3 Replies View Related

DATEDIFF Return Monday - Friday Or Just Weekdays

Aug 30, 2006

I have a query and am trying to just return the difference between two dates but not include weekends.For instance, if I have 08/21/2006 - 08/28/2006, there are 6 weekdays.  I tried this, but I am getting 7 as a result.SELECT DATEDIFF(weekday, request_start_date, request_end_date) AS days_off, request_id
FROM request Any help would be greatly appreciated.

View 2 Replies View Related

T-SQL (SS2K8) :: Set Shipment Date To Monday Instead Of Thursday?

Oct 27, 2014

In my below T-sql the shipment date is set to next Thursday, if the shipment is missed in current week. Now, I've to change the t-sql code to change the shipment dates to Monday instead of Thursday.

USE tempdb;
GO
DECLARE @Date DATE;
SET @Date = GETDATE();
--SET @Date = '2014-07-25';
DECLARE @TEST_DATA TABLE

[code]...

View 6 Replies View Related

Query To Show Time Monday To Sunday?

Jul 17, 2014

I would like to show employee work hours daily from Monday to Sunday. I have managed to write a query to get the total hours.

This is the query giving total hours from and to date.

(select sum(t.timespent)/60 from timeitems t
where t.employee = e.code
and t.project = p.code
and t.ndate >= '2014-07-15'
AND t.ndate <= '2014-07-15') as Hours
from projemplink pl

View 1 Replies View Related

Set Default Parameter Value Monday Through Friday Of Last Week.

Dec 6, 2007



I have a weekly report that i want to display mon tues wed thur and fridays date from last week.

I know how to specifically pick one date:

=DateAdd(DateInterval.Day, -6,DateAdd(DateInterval.Day, 1-Weekday(today),Today))


that would set the parameter to monday. But how to do i make it select all the dates from monday-friday of the previous week?

View 7 Replies View Related

SQL Server 2008 :: How To Retrieve Only Monday Dates From Each Month

Jan 23, 2015

How to retrieve only Monday dates from each month in sql server.

If i pass any value (Let say GETDATE()) then i should get all monday values from the current month.

I want to calculate bi weekly range data in the sql.

View 9 Replies View Related

Transact SQL :: How To Generate Week Ranges From Monday To Sunday

May 28, 2015

I need to generate the week ranges like this format :

Here from date and to date would be picked up from the table but just to make you understand i have hard coded it but this is the real date which is falling inside the table. 

Note : Week should be generated from Monday to Sunday within desired date range

View 6 Replies View Related

Monday To Sunday - No Data For A Sunday Being Displayed

Sep 15, 2013

I have written a piece of SQL which I thought was wokring fine. I wanted to show all data for the current week from Monday - Sunday

I wanted to pick up all data from Monday 00:00:01 to Sunday 23:59:59 and then when the data runs again on the next Monday, a completley new set of data starts to be loaded in

On the off chance I have come into work today and realise that no data is being diaplyed, and today is a Sunday

I know for a fact that my SQL will pick up data as soon as it hits 00:00:01 tonight

I really want my SQL to pick up data for a Sunday

BETWEEN DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) AND DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 6)

View 1 Replies View Related

Transact SQL :: How To Get Date - Last Monday From Given Date

Jun 15, 2015

How can I get a date that would be last/previous Monday from given date?

For example for given 22/01/2015 it would give 19/01/2015.

View 16 Replies View Related

SIMPLE Command To Convert String To Number? Not CAST Or CONVERT.

Aug 15, 2006

Dear Experts,Ok, I hate to ask such a seemingly dumb question, but I'vealready spent far too much time on this. More that Iwould care to admit.In Sql server, how do I simply change a character into a number??????In Oracle, it is:select to_number(20.55)from dualTO_NUMBER(20.55)----------------20.55And we are on with our lives.In sql server, using the Northwinds database:SELECTr.regionid,STR(r.regionid,7,2) as a_string,CONVERT(numeric, STR(r.regionid,7,2)) as a_number,cast ( STR(r.regionid) as int ) as cast_to_numberFROM REGION R1 1.00112 2.00223 3.00334 4.0044SELECTr.regionid,STR(r.regionid,7,2) as a_string,CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,cast (STR(r.regionid,7,2) as numeric ) as cast_to_numberFROM REGION R1 1.00112 2.00223 3.00334 4.0044Str converts from number to string in one motion.Isn't there a simple function in Sql Server to convertfrom string to number?What is the secret?Thanks

View 4 Replies View Related

How To Get Starting Datetime(monday) Of The Week And Ending Datetime Of The Week(sunday)

May 2, 2007

hi friends,



how to get the date of the first/last day of the week in sql...

can any one help me





Cheers,

raj

View 5 Replies View Related

Select Convert(varchar(16), Getdate(), 101)+LEFT(REPLACE(convert(varchar, Getdate(), 108), ':', ''),4)

Sep 26, 2007



select convert(varchar(16), getdate(), 101)+LEFT(REPLACE(convert(varchar, getdate(), 108), ':', ''),4)

From above query I get

mmddyyyyhhmm

but it' s yyyy and hour can not be separated

04/12/200702:05

How can I separated the year and hour ?

Thanks
Daniel

View 2 Replies View Related

Convert Mdf To Mdb

Jul 29, 2007

hi all,
I'm using visual web developer and created a project with a mdf data file. how can I convert this file to MS ACCESS mdb file?
 Thanks

View 3 Replies View Related

Convert .MDF To .bak

Oct 3, 2007

hi friends i am using vwd 2005 i created a project now i want to upload it on the server, but i want which database i used in the database convert it into .bak file for upload it on the server how i convert it, i don't have MS SQL SERVER 2005 or any except vwd 2005.

View 1 Replies View Related

Convert

Nov 1, 2007

how to convert msaccess 2003 data to sqlserver 2005

View 1 Replies View Related

How To Convert?

Jan 29, 2008

Hi all,
 
  How to convert varchar value to int in SQL Server2000?
  For example i'm having the varchar value '1,2,3,4'
  i want to convert this to 1,2,3,4 that is i want to remove single quote (') at the start and end of the varchar value,
  how to do this?
 
Thanks!

View 5 Replies View Related

Help Me Convert This.

Mar 6, 2008

 Hello! I need help to change this to @@Identity..Thanks!     protected void Button2_Click(object sender, EventArgs e)    {       
SqlConnection con = new
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ThesisConnectionString"].ToString());        con.Open();       SqlCommand com1 = new SqlCommand();        com1.Connection = con;        com1.CommandText = "Insert into TransactionHeader values ('" +  DateTime.Now + "', '"            + DropDownList1.SelectedValue + "', '"            + TextBox1.Text + "', '"            + TextBox4.Text + "', '"            + TextBox9.Text + "', '"            + TextBox11.Text + "', '"            + TextBox12.Text + "');select scope_identity() as returnidentity";            string xyz = Convert.ToString(com1.ExecuteScalar());                               DataTable dt = (DataTable)Session["shoppingCart"];        for (int i = 0; i <= dt.Rows.Count - 1; i++)        {            String WasteType = dt.Rows[i][0].ToString();            double Volume = double.Parse(dt.Rows[i][1].ToString());            double Fees = double.Parse(dt.Rows[i][2].ToString());            double total = Volume * Fees;            SqlCommand com = new SqlCommand();            com.Connection = con;            com.CommandText = "Insert into TransactionDetail values ('" + xyz + "', '"                + WasteType + "', '"                + Volume + "', '"                + total + "')";            com.ExecuteNonQuery();            ClientScript.RegisterStartupScript(GetType(), "save", "alert('Record Saved');", true);        }                                 }  

View 2 Replies View Related

Convert() Help...

May 24, 2004

How can I convert a date to MMDDYY with Convert()?

View 3 Replies View Related

How To Convert This?

Jun 18, 2004

Hi, I am new to Sql.

My question is how to convert nvarchar like this "Wed Jun 16 19:14:23 2004 GMT" to standard datetime format?


Thanks!

View 2 Replies View Related

Convert

Nov 15, 2001

Hi,

Can anyone tell me, how can I get the date format in YYYYMMDDHHMISS format.
For Ex: select convert(char(12),getdate(),112) gives me the result as
'20011115'. Now, how can I get the the result something like '20011115110020'?

View 3 Replies View Related

Convert From Hex

May 24, 2001

If I do a query from SQL 7.0 and get the result "10" which is a hex value (0x0A), how do I convert this using something like convert or cast to show "a"
Is there anywhere that I can look for help? I can get it to show 0x0A using cast, but that is not what I want. I want a hex number without 0X0 in front of A. The A I can convert using something like Lower(A)

Thank you.

View 1 Replies View Related

Convert

Oct 11, 2001

Hi, I am trying to convert 2 columns from varchar(255) to datetime, the format of the data in the columns is '02/02/2001', and 1 column from varchar(255) to money, the format of the data in this column is '12,340.00'.

When I run : select convert(datetime, Col004), convert(datetime, Col005), convert(money, Col007) from table1

I get a result upto 59,996 rows then get the error:

Syntax error converting datetime from character string.

Any help would be appreciated, I have to convert 4 tables with, 722834, 1113978, 115489 and 121983 rows respectivly.

View 3 Replies View Related

Convert

Jun 2, 1999

Is there a way to install MS SQL 6.5 twice on the same server? I would like to install SQL into the following dorectories D:MSSQL and D:MSSQL2. Any help would be appreciated.

View 5 Replies View Related

Convert To T-SQL

Sep 24, 2004

can anybody convert this to T-SQl :

Select decode(trunc((d_vst_btcdte - nvl(n_per_birth,d_vst_btcdte))/10000,0),0,'no DOB',
14,'14-16',15,'14-16',16,'14-16',
17,'17-20',18,'17-20',19,'17-20',20,'17-20',
21,'21-25',22,'21-25',23,'21-25',24,'21-25',25,'21-25',
26,'26-30',27,'26-30',28,'26-30',29,'26-30',30,'26-30',
31,'31-35',32,'31-35',33,'31-35',34,'31-35',35,'31-35',
36,'36-40',37,'36-40',38,'36-40',39,'36-40',40,'36-40',
41,'41-45',42,'41-45',43,'41-45',44,'41-45',45,'41-45',
46,'46-50',47,'46-50',48,'46-50',49,'46-50',50,'46-50',
51,'51-55',52,'51-55',53,'51-55',54,'51-55',55,'51-55',
56,'56-60',57,'56-60',58,'56-60',59,'56-60',60,'56-60',
61,'61-65',62,'61-65',63,'61-65',64,'61-65',65,'61-65',
66,'66-70',67,'66-70',68,'66-70',69,'66-70',70,'66-70',
'71+') AGE

View 1 Replies View Related

Convert To T-SQL

Oct 12, 2004

Can anybody convert to T-SQL;
select distinct to_char(sysdate,'FMDAY, MONTH DD, YYYY HH:FMMIAM') TODAY
, d_aaa_insthdg CNTRHD
, decode(trunc((d_vst_btcdte - nvl(n_per_birth,d_vst_btcdte))/10000,0),0,'no DOB',
14,'14-16',15,'14-16',16,'14-16',
17,'17-20',18,'17-20',19,'17-20',20,'17-20',
21,'21-25',22,'21-25',23,'21-25',24,'21-25',25,'21-25',
26,'26-30',27,'26-30',28,'26-30',29,'26-30',30,'26-30',
31,'31-35',32,'31-35',33,'31-35',34,'31-35',35,'31-35',
36,'36-40',37,'36-40',38,'36-40',39,'36-40',40,'36-40',
41,'41-45',42,'41-45',43,'41-45',44,'41-45',45,'41-45',
46,'46-50',47,'46-50',48,'46-50',49,'46-50',50,'46-50',
51,'51-55',52,'51-55',53,'51-55',54,'51-55',55,'51-55',
56,'56-60',57,'56-60',58,'56-60',59,'56-60',60,'56-60',
61,'61-65',62,'61-65',63,'61-65',64,'61-65',65,'61-65',
66,'66-70',67,'66-70',68,'66-70',69,'66-70',70,'66-70',
'71+') AGE
, sum(decode(d_vst_dontyp,'WB',1,0)) DRAW1
, sum(decode(d_vst_dontyp,'xx',1,1)) TOTAL0

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved