DatePart Returning Incorrect Value For Weekday (dw)

Feb 18, 2008

Hi All,
In ASP.Net, I am passing a date as a string formatted as yyyymmdd (e.g. 20080219) via an SqlParameter as follows:
aSqlParams(0) = New SqlParameter("@DepartDate", inpDepartDate.Value)
In the Stored Procedure (SP) I am using DATEPART(dw, @DepartDate).
If I execute the SP from within SQL Server and enter a date, formatted as above, as tha value for the Parameter @DepartDate then DatePart returns the correct value (3).
If I use the SP via ASP.Net it returns a value which is 1 less (2).
 When I execute the SP manually the resultant EXEC statement uses "@DepartDate = N'20080219'". Can something similar be done in ASP.Net when setting the SqlParameter?
 
Thank you,

View 4 Replies


ADVERTISEMENT

Group By WEEKDAY And ORDER By WEEKDAY

Jan 31, 2014

I try to make the following:

select DATENAME(WEEKDAY,[date]) as DAY, sum(earnings) as Earnings
from myTable
where DATENAME(WEEKDAY,[date]
in ('monday','tuesday','wednesday','thursday','friday')
group by DATENAME(WEEKDAY,[date])
order by DAY

this query works very well except the last line. the last line causes SQL-Server to order the days in an alphabetical order.What do I have to do that SQL-Server orders the days according to their natural appearance (monday, tuesday, wednesday, thurs......)

View 2 Replies View Related

SqlDataReader Returning Incorrect Results

Oct 23, 2006

I am/have been having an issue with Data Access from a Sql Server database. I have a class that contains a method called "GetDataReader" which takes in a string for the query. Occasionally, the DataReader returned has completely different columns thus resulting in an error when trying to read the data. Below is a small section of code that actually creates the datareader, opens the connection and executes the reader.SqlCommand cmdReader = new SqlCommand();
SqlDataReader drReturn = null;
try {
// Set the connection for the command object
cmdReader.Connection = new SqlConnection(this._csbGlobal.ConnectionString);
cmdReader.Connection.Open();
// Set the command type
cmdReader.CommandType = Type;
// Set the command text
cmdReader.CommandText = Sql;
// Set the command timeout
cmdReader.CommandTimeout = _iTimeout;
if (Parameters != null) {
// Set the parameters
for (int i = 0; i < Parameters.Count; i++) {
cmdReader.Parameters.AddWithValue("@" + Parameters.GetKey(i), Parameters[i]);
}
}

// Get the return value
drReturn = cmdReader.ExecuteReader(CommandBehavior.CloseConnection);
// Dispose of the command object
cmdReader.Dispose();
cmdReader = null;
} catch (SqlException e) {
this.HandleError(e);
} catch (Exception e) {
this.HandleError(e);
}
// Return the reader
return drReturn;The data access class is created on each page and only used for that page and any usercontrols on that page. I have checked all the datareaders and they are all being closed. I have been fighting with this issue for about a month and a half now. It only seems to happen when there are a lot of people on the site.If anyone has experienced this or konws how to fix it please let me know. Thanks-Jason

View 5 Replies View Related

SQL Command Returning Some Incorrect Records

Nov 13, 2006

I am fairly sure that I am just overlooking something, but the following command is returning some incorrect fields. 
SqlDataSource1.SelectCommand = "SELECT ITNBR, (SELECT ITDSC FROM AMFLIBT.ITEMASA WHERE AMFLIBT.ITEMASA.ITNBR = AMFLIBT.ITEMBL.ITNBR) AS ITDSC, SUM(MOHTQ) AS Balance, (SELECT VNDNR FROM AMFLIBT.ITEMASA WHERE AMFLIBT.ITEMASA.ITNBR = AMFLIBT.ITEMBL.ITNBR) AS VENDOR FROM AMFLIBT.ITEMBL WHERE VNDNR = @DDLVNDNR GROUP BY ITNBR, VENDOR"
SqlDataSource1.SelectParameters.Add("ddlvndnr", ddl1.SelectedValue)
I have more code to show, if this looks correct.  Just let me know.
Thanks in advance.

View 2 Replies View Related

Transact SQL :: Insert Trigger Returning Incorrect Results

Jul 11, 2015

SQL Version:  SQL2014

PROBLEM:  The SQL insert trigger code below is returning incorrect results.  In some cases the results returned are from entirely different fields than those specified as the source field in the SET statement.  For instance the value returne for the Price_BeforeAdj field does not = 20000000?  It returns a NULL.  See code below.

OFFENDING CODE:

ALTER TRIGGER [dbo].[xcti_WIPAdjustments_I]
   ON  [dbo].[budxcWIPAdjustments]
AFTER INSERT AS
BEGIN
 SET NOCOUNT ON;
  UPDATE budxcWIPAdjustments

[Code] ....

View 11 Replies View Related

WeekDay Defaults...

Feb 27, 2001

Hi!
Im experiencing problems with datepart(weekday,...) function. In particular with week 54 of 2000... (by the way, dont make a bet about that, because Jan 1st. was saturday (last day of week) and year 2000 was a leap year!!!, so Dec 31 became the one and only case of 54 weeks... in our calendar).
Is there a way I can fix sunday as first day of week, instead using SET DATEFIRST in every procedure? (because "somebody" puts MONDAY as a default in spanish)
Thanx in advance,
Csar.

View 1 Replies View Related

Weekday Report

May 29, 2008

Hello Guys,

I'm going crazy tring to figure out how to generate a report that execute a Store procedure and then give me a total Per WeekDay and group it by Part Number.

For example my data should look like this

(PartNumber-Monday-Tuesday-Wednesday-Thursday-Friday-Saturday-Sunday-)

The report will give me a list of all available part and the sold sold per part per day.



Thanks in Advance.

View 8 Replies View Related

Weekday Names

Jan 4, 2007

Sql server 2000 -sql query analyzerselect datename(dw,'01-01-2006')returns sundayNow I do:set language danishselect datename(dw,'01-01-2006')returns sonday. But it should be sndag. Same goes forsaturday/lordag/lrdagTried substring'ing and ascii'ing/unicode'ing and it is AFAIK an o insteadof the special danish character .Is this a "feature" or am I doing something wrong?I "solved" it by doingselect case DATENAME(dw,'01-01-2006') WHEN 'lordag' THEN 'lrdag' WHEN'sondag' THEN 'sndag' ELSE DATENAME(dw,'01-01-2006') ENDbut it sure aint pretty./jim

View 3 Replies View Related

Calculating Weekday Of A Date

Nov 25, 2013

Aim – To work out what day of the week a Closedate Falls on

Date format is of Closedate is “Year-month-Day” (varchar(50)

E.g.
2013-11-25
2013-11-21
2013-11-19
2013-11-18

Desired results
2013-11-25Monday
2013-11-21Thursday
2013-11-19Tuesday
2013-11-18Monday

View 3 Replies View Related

Average Transactions By Weekday

Jan 25, 2008

Hi,

I have a transaction file containing a year's worth of transactions with a date/time field that tells me when the transaction took place. I'd like to write a view (or perhaps multiple views) that tells me the average number of transactions per weekday.

I've been messing around with DATEPART and I can calculate the *total* number of transactions that took place on a Monday, for example, but I can't figure how to do the *average* number. My problem seems to be calculating the number of Mondays there were in the year. Or overthinking it.

Any suggestions would be greatly appreciated.

Thanks,

Jennifer

View 5 Replies View Related

Convert Day Of Week Integer To Weekday Name?

Sep 10, 2007

In a table, I store an integer to represent a day of the week (1 = sunday ) and then in procedures, compare that to datepart(dw, getdate()) to do alternative tasks on certain days.

If I have the number 1, is there a built in function to convert that to sunday or should one just write a function to do just that?

View 3 Replies View Related

Display Date And Weekday In A Different Language

Oct 4, 2007

How can I set a different language (for example swedish) when using WeekdayName,

DatePart and FormatDateTime?

View 2 Replies View Related

Reporting Services :: SSRS Datetimepicker And Textboxes Values Different When Using Weekday Function?

May 7, 2015

In my SSRS report i have a date parameter and i want to set to it a default value with a complicated logic. I arrived at this strange behaviour:

Today is May 6th, wednesday. If i use the following expression:

DateAdd("d",Weekday(Today(),DayOfWeek.Sunday),Today())

for the default time picker I get May 9th. If I use exactly the same expression in a textbox in the same report

DateAdd("d",Weekday(Today(),DayOfWeek.Sunday),Today()).ToLongDateString()

I get May 10th! The only thing that changes is the toString. Why are the two values different? I tried with different expressions and the difference arises when i start using Weekday(Today(), somevalue).

The result of Weekday should be independent from regional settings as I am forcing Sunday to be the first day of the week, right?

View 2 Replies View Related

DATEPART???

Jan 31, 2008

I have a datetime field in a sql db named "arrdate". For what I am doing I only need to extract the date formatted as mm/dd/yyyy. Can someone give me an example of the proper syntax?
Something like seems like it should work:
SELECT id, DATEPART(mm/dd/yyyy, arrdate)
FROM guest
but of course it doesn't.....

View 3 Replies View Related

Datepart

May 7, 2001

Why would this return a year of 1905: If @tempdate was a varchar
it would return just 2001, but by it being a dateime it returns
the year 1905.

declare @tempdate datetime
select @tempdate = (select datepart(yy,getdate()))
select @tempdate

View 4 Replies View Related

DatePart

Mar 18, 2006

Datepart function is different from general ms using in MSSQL

I need something like this

DatePart ( interval, date, [firstdayofweek], [firstweekofyear])

I try to get which week of year.. but first day of week for some country is not sunday..

How can I determine that the first day of week is monday?

View 1 Replies View Related

DatePart

Apr 21, 2008

CREATE PROCEDURE [dbo].[sp_TRAK_PROG_TOTALS]
@Frequency varchar (1),
@Rpt_Yr smallint,
@Prog_Yr varchar (2)
AS

SET NOCOUNT ON
DECLARE
@PROG1VARCHAR (20),
@PROG2VARCHAR (20);
--@PROG_YR VARCHAR (2);

SET @PROG1 = 'TRAK08'
SET @PROG2 = 'TRAK208'
SET @PROG_YR = Select DatePart(YY, GetDate()) as Current_Year


SELECT @Rpt_Yr = case @Frequency
WHEN 'M' then (select dateadd(mm,datediff(mm,0,getdate())-1,0))
WHEN 'O' then convert(varchar,@Start_Date,101) + ' 00:00:00'
ELSE convert(varchar,getdate()-1,101)
end
--------------------------------------------------------------------------------------------------
I have done most ot the script for the rest of my pgoram but I am having problems with the date requirements.
I was told to parse the year so that the user can enter the 2 digit date.

When it is 'O' (other) was told build a string to parse the year using datepart so that the user can enter the program year (2 digit format). (@Rpt_Yr)
When it is 'M' (monthly) then I am to goto to table tk_prog get the active program
I have no clue how to correct the above.

View 2 Replies View Related

Help With Datepart

May 31, 2008

Hi All,

i'm trying to format SQL so that I retrive the day of the week and the hr in the same column.

SELECT Datepart([hour], Time) as Hour, SUM(Total) as Sales, count(TransactionNumber) as Customers, SUM(Total)/count(TransactionNumber) as 'Ave Sale'
FROM [transaction]
WHERE time between '05/30/2008' and '05/31/08'
GROUP BY datepart([hour],Time)

Output desired is

05/30/08 09
05/30/08 10
05/30/08 11
...

View 1 Replies View Related

DATEPART

Mar 9, 2006

Hi , I am converting a datetime field to a string. The column is called DateScanDate.

This is my query;

SELECT CAST(DATEPART(Year, DateScanDate) AS VARCHAR(4)) + CAST(DATEPART(Month, DateScanDate) AS VARCHAR(2))+
CAST(DATEPART(Day, DateScanDate) AS VARCHAR(2))+ CAST(DATEPART(Hour, DateScanDate) AS VARCHAR(2))+ CAST(DATEPART(Minute, DateScanDate) AS VARCHAR(2))FROM HAAneurysmScan

I would like the month of March to be '03' instead of '3' and the 9th day of the month to be '09' instead of '9'
How can I do this?
regards
ICW

View 9 Replies View Related

Help With Datepart

May 3, 2007

I would like to take the following code and display the data / count by month. I want to see how many people are logging in by month.. I tried using the datepart but I keep getting an aggrefate comannd error can anyone help modify this query

SELECT DISTINCT Count(login.login_time) AS CountOflogin_time
FROM login
WHERE login.login_time>=#10/1/2005#;

Thanks,

View 4 Replies View Related

Datepart

Sep 28, 2007

Using MS Reporting Services 2005
I have this expression in my field in my table and in my group by expression field

=Monthname(Datepart("m", Fields!CreatedDate.Value))

ok this gives me the month eg July etc

=Datepart("yyyy", Fields!CreatedDate.Value)

ok this gives me the year eg 2006 etc


if I try to add the two together I get the error (not in correct format) obviously as one is numeric and one alpha

=(Monthname(Datepart("m", Fields!CreatedDate.Value) & " " & (Datepart("yyyy", Fields!CreatedDate.Value))))

or I can do this:


=(Datepart("m", Fields!CreatedDate.Value) + (Datepart("yyyy", Fields!CreatedDate.Value)*100))

which gives me 200607

what do I need to do to have this show as

July 2006 etc

thanks
Dianne

View 4 Replies View Related

Datepart Help

May 30, 2008

How can I concat. these two into one column?


datepart(mm,DateCol), datepart(dd,DateCol) as MyDate



thanks.

View 7 Replies View Related

Datepart?

Oct 9, 2007



Hi everyone, Im currently using SSRS 2000. I have a report that pulls data since 2001. I used Datepart('m", Fields!Shipped_Date.Value) to break it down into months. It works except that it doesnt separate the year. It'll group all of january together but 2001,2002,2003, etc, together. Then when I used Y to break it down by year, it does break it by year but keeps all the months together.....well what I want is to be able to have it jan 2001, feb 2001, jan 2002, separately group. Hope I didnt confuse anyone. All pointers welcomed.


Thanks,

Abner

View 1 Replies View Related

Max With Datepart

Aug 22, 2006

I am wanting to set any given @Date parameter to the most current recorded Monday in a table (tblMarketPricing). Would this work:

@Date = Max(Datepart(dw,MktDate) IN 2

I am unsure if you can use Max with the Datepart function.

***If this is not allowed, can anyone suggest anything different that I might try?

View 3 Replies View Related

DATEPART....part Two??

Jan 31, 2008

ok, following up on my previous post that I marked as answered a little premature. The query below works fine in sql studio:
SELECT id, CONVERT(NVARCHAR(10), arrdate,101) as formatedDate
FROM guest
but when I try to use it in a c# code behind file:
comm = new SqlCommand("SELECT id, CONVERT(NVARCHAR(10), arrdate,101) as formatedDate FROM guest WHERE id = @id", conn);
it bombs??

View 5 Replies View Related

Trouble With DatePart

Feb 22, 2005

I'm trying to get just the day part of the date - 2/22/2005 (getdate()) but instead of returning '22', it's returning '2'. Can someone please tell me what I'm doing wrong?

Thanks!
Lynnette

Here's the code

declare @thisDay varchar
set @thisDay = Convert(varchar, Datepart(day, getdate()))

View 3 Replies View Related

Using DatePart Function In SQL

Apr 9, 2006

Hello dears;
I wanted to use DatePart function in an SQL statement using objectDataSource to extract the year only from a Date field, then populating only the years in Dropdown list, but it didn't worked. Is is possible to to use that function in an SQL statment.?
Thanks alot
VWD 2005
 

View 2 Replies View Related

UPDATE And DatePart

Aug 24, 2001

I am updating a demo system and need to bring all the dates with 1998 to 2000 and 1999 to 2001.

Im trying something like this but cant get it work.

UPDATE mytable SET datepart(yyyy, mydate) = '2000' WHERE mydate BETWEEN '01/01/1998' AND '12/31/1998'

How can I get this to work, or am I totally off?

Thanks,Adrian

View 4 Replies View Related

DATEPART Help Needed Please!

Jul 30, 2001

I am inserting two fields like this (TimeStamp):

7/30/01 1:26:01 PM

The first one needs to be the Date part, the second one needs to be the Time part. Anyone know who to do this? I saw DATEPART in SQL BOL but it didn't really show me.

TIA,

Bruce

View 1 Replies View Related

Between Statement With Datepart

Sep 19, 2000

We are looking on how to do a between statement for comparing only month and days(such as birthday.) The proc will be fed 2 parameters and we want to check if a date field (only the month and day) fall between the parameters. Such as the parms are 09/01/2000 and 10/31/2000
I want to return all records where the date field is
between 09/01/xxxx and 10/31/xxxx. I tried the datepart function but couldn't find a way to combine them. Any solution greatly appreciated.

View 9 Replies View Related

DTS DatePart Errors.

Feb 24, 2000

Hi,

I am having trouble trying to get a "week number" from a date field to store into a numeric table.

I have inserted the following into my DTS ActiveX code;
DTSDestination(15)=DatePart( wk , DTSSource(1) )

When I run the code the following error is shown;
ErrorDescription: Invalid procedure call or argument: ''DatePart'

Q - Does DatePart work in DTS ActiveX ?
Q - Is my syntax correct ?

david

View 1 Replies View Related

Datepart Month

Dec 16, 2003

I am converting a datetime value to char using datepart(mm,datefield).

I would like the month to be 2 digits - 01,02,03...11,12 - but it only returns 1,2,3...11,12. What can I add to do this? thanks in advance.

View 1 Replies View Related

Smalldatetime/Datepart

Aug 17, 2004

Will someone please tell me how to pull the time out of a smalldatetime field.
The code i am trying to use is as follows:

Select datepart(hh:mm, TimeField1)
from table1;

This gives me an error. I have also tried datepart('hh:mm'... datepart("hh:mm"... and other variations but i cant get anything to work. Thanks in advance for any help!!

View 2 Replies View Related







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