Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MS SQL Server


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





SQL Server 2005 Query With Date Function


I wrote a function and a SQL to get the  3 columns Date,Total Orders
& Amount, for dates between Date Started and Date Completed if I
pass different Dates in the SQL I get the correct result but if I pass
same dates then I don't get the result I am looking for .

For Instance,if I give Date From=1/02/2008 ;Date To=1/8/2008(Different dates )I am getting values for all the three columns.
But I give same dates for  Date From=01/02/2008 ;Date To=01/02/2008 then I am not getting the records.

Some how I could not trace what could be the error in my SQL /Function.

I appreciate if I could get some work around for this.

Thanks!
 
 
Function:create function dbo.CreateDateList(@start datetime, @end datetime)
returns @t table ( [date] datetime )
as
begin
if @start is null or @end is null
return

if @start > @end
return

set @start = convert(datetime, convert(varchar(10), @start, 120), 120)
set @end = convert(datetime, convert(varchar(10), @end, 120), 120)

while @start < @end
begin
insert into @t ( [date] ) values (@start)
set @start = dateadd(day, 1, @start)
end

return
end

---------SELECT qUERY----------

SELECT Convert(Varchar(15), l.[date],101)as Date,COUNT(o.OrderID ) AS TotalOrders,ISNULL(Round(SUM(o.SubTotal),2),0) AS Amount , 1 as OrderByCol
FROM dbo.CreateDateList(@DateFrom , @DateTo) l
LEFT OUTER JOIN orders o ON o.Datecompleted >=Convert(Datetime, l.[date],101) and o.Datecompleted < dateadd(day,1,convert(Datetime, l.[date],101))
WHERE StoreID=@StoreID GROUP BY Convert(Varchar(15), l.[date],101)
Union
SELECT 'Grand Total' as Total,NULL AS TotalOrders, ISNULL(Round(SUM(o.SubTotal),2),0) AS Amount, 2 as OrderByCol
FROM dbo.CreateDateList(@DateFrom , @DateTo) l
LEFT OUTER JOIN orders o ON o.Datecompleted >=Convert(Datetime, l.[date],101) and o.Datecompleted < dateadd(day,1,convert(Datetime, l.[date],101))
WHERE StoreID=@StoreID
Order by Date


 
 
 




View Complete Forum Thread with Replies

Related Forum Messages:
SQL Server 2005 Query/trigger/function (whatever It Is That I Need)
Hey guys maybe you can help me out, been trying to figure this one out all day at work. I know how to use columns in a table to calculate another column in that same table. But I need to do some math on columns from a totally seperate table. Here is my scenario
 table 1 = stock table
 table 2 = Purchase order table
 in table 2 there are line items that have ordered quantities for parts that we have ordered
 in table 1 under each part number is a field for "quantity on order"
I need to compute the "quantity on order" in table 1 by summing all of the quantities in table 2 where the partnumber = the partnumber from table 1
 
quantity on order (table 1) = sum of all quantities (table 2) where the part numbers match
so for part number 516 i have this
 
table 2
poNumber             partNumber                 quantity
1                             516                             1
2                             516                             12
3                             516                             4
 
table 1
partNumber            inStock              onOrder
516                          0                        17(this is what i am trying to figure out how to compute)
 
any help on this qould be appreciated. I would like the database to automatically do this itself if at all possible.

View Replies !
SQL Server2005 Query &#043;Date Function
I wrote a function and a SQL to get the 3 columns Date,Total Orders & Amount, for dates between Date Started and Date Completed if I pass different Dates in the SQL I get the correct result but if I pass same dates then I don't get the result I am looking for .

For Instance,if I give Date From=1/02/2008 ;Date To=1/8/2008(Different dates )I am getting values for all the three columns.
But I give same dates for Date From=01/02/2008 ;Date To=01/02/2008 then I am not getting the records.

Some how I could not trace what could be the error in my SQL Function.

I appreciate if I could get some work around for this.

Thanks!



create function dbo.CreateDateList(@start datetime, @end datetime)
returns @t table ( [date] datetime )
as
begin
if @start is null or @end is null
return

if @start > @end
return

set @start = convert(datetime, convert(varchar(10), @start, 120), 120)
set @end = convert(datetime, convert(varchar(10), @end, 120), 120)

while @start < @end
begin
insert into @t ( [date] ) values (@start)
set @start = dateadd(day, 1, @start)
end

return
end

**********SELECT qUERY***********

SELECT Convert(Varchar(15), l.[date],101)as Date,COUNT(o.OrderID ) AS TotalOrders,ISNULL(Round(SUM(o.SubTotal),2),0) AS Amount , 1 as OrderByCol
FROM dbo.CreateDateList(@DateFrom , @DateTo) l
LEFT OUTER JOIN orders o ON o.Datecompleted >=Convert(Datetime, l.[date],101) and o.Datecompleted < dateadd(day,1,convert(Datetime, l.[date],101))
WHERE StoreID=@StoreID GROUP BY Convert(Varchar(15), l.[date],101)
Union
SELECT 'Grand Total' as Total,NULL AS TotalOrders, ISNULL(Round(SUM(o.SubTotal),2),0) AS Amount, 2 as OrderByCol
FROM dbo.CreateDateList(@DateFrom , @DateTo) l
LEFT OUTER JOIN orders o ON o.Datecompleted >=Convert(Datetime, l.[date],101) and o.Datecompleted < dateadd(day,1,convert(Datetime, l.[date],101))
WHERE StoreID=@StoreID
Order by Date

View Replies !
Using A Date Function To Declare A Variable Used In A SQL Query
Hi all can you help me, I know that I am doing some thing wrong. What I need to do is set a variable to the current date so I can use it in a SQL query to an access database. This is what I have so far
<script runat="server"">
Sub Page_Load
dim --all the variables for my sql connections--
dim ff1 As Date
then my sql connection and queries
sql="SELECT FullRate, " & ff1 &" FROM table1 WHERE hotelnumber = " & hotel
This works is I set ff1 as a string and specify the string (my column headings are set as dates in my table)
dim ff1 As string
ff1="30/01/2006"
but I need ff1 to be the current date and is I use ff1 As date it returns time and date
Is there any way to set ff1 to the current date in this format "dd/mm/yyyy"
 
Any help is greatly appreciated

View Replies !
Visual Studio Query Designer Date Function Bug?
In the Visual Studio Query designer against a ce 3.1 sdf file, if I type in

SELECT     DATEPART(yyyy, GETDATE()) AS Expr1
FROM         CropYear

The designer updates it to

SELECT     [DATEPART](yyyy, GETDATE()) AS Expr1
FROM         CropYear

Which results in an error

SQL Execution Error. 

Executed SQL Statement: SELECT [DATEPART](yyyy, GETDATE()) AS Expr1 FROM CropYear

Error Source: SQL Server Compact Edition ADO.NET Data Provider

Error Message: There was an error parsing the query. [Token line number = 1, Token line offset = 19, Token in Error = (]

The original query works fine as long as I don't user the query designer to edit it. 

The same problem occurs with DATEADD, DATEDIFF and DATENAME.

Any ideas?

Thanks

Judah

View Replies !
How To Use Date Function In Sql Server
HiI am trying to do a simple select using a date value.For eg:-in oracle i would do the followingselect count(*) from TEMP_TABLE where to_char(modif_time,'mm/dd/yyyy')='10/04/03'How do I accomplish the same in sqlserver?Thanks in Advancesk

View Replies !
What Is Equivalent Of Format(date) Function Of MS Access In MS Sql Server 2000
Hi All,I am facing a problem with a sql what i used in MS Access but its notreturning the same result in MS Sql Server 2000. Here i am giving thesql:SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHEREMY_ID=1The above sql in ACCESS return me the date in below format in onecolumn:Friday 09, 2003But in Sql server 2000 i am not getting the same format eventhough iam using convert function, date part function etc.Please if you find the solution would be helpful for me..ThanksHoque

View Replies !
ROW_NUMBER() Function Is Not Recognized In Store Procedure.(how To Add ROW_NUMBER() Function Into SQL SERVER 2005 DataBase Library )
Can anybody know ,how can we add  builtin functions(ROW_NUMBER()) of Sql Server 2005  into database library.
I get this error when i used into storeprocedure :
ROW_NUMBER() function is not recognized in store procedure.
i used MS SQL SERVER 2005 , so i think "ROW_FUNCTION()" is not in MS SQL SERVER 2005 database library.
I need to add that function into MS SQL SERVER 2005 database library.
Can anbody know how we can add that function into MS SQL SERVER 2005 database library?
 

View Replies !
Problem Inserting Integers And Date In A Sql Server 2005 Datatable Row And Selecting It Afterwards Based On The Date
Hi,
 
I have soma ado.net code that inserts 7 parameters in a database ( a date, 6  integers).
I also use a self incrementing ID but the date is set as primary key because for each series of 6 numbers of a certain date there may only be 1 entry.  Moreover only 1 entry of 6 integers is possible for 2 days of the week, (tue and fr).
I manage to insert a row of data in the database, where the date is set as smalldatetime and displays as follows:  1/05/2007 0:00:00 in the table.
I want to retrieve the series of numbers for a certain date that has been entered (without taking in account the hours and seconds).
A where clause seems to be needed but I don’t know the syntax or don’t find the right function
I use the following code to insert the row :
 
command.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime, 40, "LDate"));
command.Parameters[6].Value = DateTime.Today.ToString();
command.ExecuteNonQuery();
 
and the following code to get the row back (to put in arraylist):
 
“SELECT C1, C2, C3, C4, C5, C6 FROM Series WHERE (LDate = Today())�
 WHERE LDate =  '" + DateTime.Today.ToString() + "'"
 
Which is the correct syntax?  Is there a better way to insert and select based on the date?
 
I don’t get any error messages and the code executes fine but I only get an empty datatable in my dataset (the table isn’t looped for rows I noticed while debugging).
Today’s date is in the database but isn’t found by my tsql code I think.
 
Any help would be greatly appreciated!
 
Grtz
 
Pascal

View Replies !
Default Date(current Date) Function W/ Update?
I have a reference table that currently has no web front-end. It's a small table(<10 rows) that's not going to change very often (maybe once every few months).

We manually update rows on the table via the GUI table interface in Enterprise Mgr., not in T-SQL.

What I'd like to do is have SQL Server automatically update the "Last_Modified" column with the current timestamp. I can do it on an Insert using the GetDate() function, but if I update a row, this doesn't work.

Is there a function I can use that can auto-populate for both insert and updates?

View Replies !
Query Not Returning Proper Data (date Related) In 2005 After Upgrade From 2000...
I am sending out an SOS. 
 
Here is the situation:
 
We recently upgrade to 2005(sp).  We have one report that ran fine in 2000 but leaves out data from certain columns (date related) in the results, so we chalked it up to being a non compatiable issue.  So, I decided to try and switch the DB back to 2000 compatibility (in our test env) and then back to 2005.  After that the report started returning the proper data.  We can€™t really explain why it worked but it did.  So we thought we would try it in prod (we knew it was a long shot) and it didn€™t work.  So the business needs this report so we thought we would refresh the test system from prod, but now we are back to square one.  I was wondering if anyone else has heard or seen anything like this.  I am open to any idea€™s, no matter how crazy. J The systems are configured identically.  Let me know if you need more information.
 
Thank you. Scott

View Replies !
Connection To SQL Server Files (*.mdf) Require SQL Server Express 2005 To Function Properly.
I dont have the SQL EXPRESS installed instead I have SQL Standard Edition.
 I have two SQL Server instances installed.
 1- UserLT (this is sql 2000)2- UserLTSQL2005 (this is SQL 2005 named instance)
But when i try to add a database to my VS website project I get the following error:
Connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly. please verify the installation of the component or download from the URL: go.microsoft.com/fwlink/?linkId=4925
I went in Tools>Opetions>DataBase tools>Data Connection>Sql Server Instance Name (blank for default)
and changed the "SQLEXPRESS" to "USERLTSQL2005".
But I still get the same error message. Any ideas how i can resolve this issue?

View Replies !
Connection To SQL Server Files (*.mdf) Require SQL Server Express 2005 To Function Properly
hello,

i've installed SQL server 2005 express and Visual web developper 2005 express.

when i whant to create a database in VWD the following error occures:

connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly. please verify the installation of the component or download from the URL: go.microsoft.com/fwlink/?linkId=49251

i searched the internet but can't find the solution, i already reinstalled my complete workstation but the problem stays.

please help!

View Replies !
Dont Think Discretization Function Is Necessary On The Analysis Service Server In SQL Server 2005
Hi, all here,

I am just wondering about the Discretization function available on analysis service server (which can not actually discretize data into user-defined expressions) . Isnt it redundant ? I mean since users can discretize their data  more meaningfully based on their own expressions in database engine of SQL Server 2005.

Thanks a lot.

View Replies !
VS2005 Error: Connection To SQL Server Files (*.mdf) Requires SQL Server Express 2005 To Function Properly.
 

Good Evening All,
 
I've serached this forum and Google'd for a resolution to this issue, to no avail.  Here's the scenario:
I'm running VS 2005 on Windows Media Center laptop and need to create ASP.net membership for my web application built using VB.  I have SQL Server Developer installed with instance name MSSQLSERVER.  Previously, I uninstalled SQL Express and installed Developer edition and can now open and utilize Management Studio.
 
Now, when I try to create a new SQL Server database in my solution's App_Data directory, I receive the above error.  I already changed instance name in VS2005 per Tools-Options-Database Tools-Data Connections to MSSQLSERVER. 
 
Could someone provide me with a list of procedures to ensure proper setup of VS2005 with SQL Server Developer Edition?
 
Thanks much for your help.

View Replies !
Split Function - Sql Server 2005
In my table, column1 having a comma separated values.I want to display in rowwise.
for example:
column1
aa,ss,ff
 
output should be
aa
ss
ff
 
Pls. help me..I want to do thr query.

View Replies !
Count Function: SQL Server 2005
is it possible to do a count on the same column but under different circumstances posting the results in two different result columns?
 

View Replies !
Sql Server 2005 GETDATE() Function
I have a small problem using the GETDATE() function from a JAVA program using the MS JDBC connector.

When I use the SQL Mangment Studio Express to execute this query:

SELECT GETDATE()
it returns 2008-04-22 16:25:03.690 which is OK !!

I want to get that same value using a Java program so I do that query but when I display it it shows as:

2008-04-22  and there is no time there !
I tried formatting the date to include time but it shows as: 04/22/2008 12:00:00 AM
So maybe the time isn´t there ?

This is the code i am using:

            Statement st = con.createStatement();
            String sql = "SELECT GETDATE()";
            ResultSet result1 = st.executeQuery(sql);

result1.next();

            Date today = result1.getDate(1);


Any help would be appreciated.

View Replies !
How To Run User Defined Function On Sql Server 2005
Dear all
I wants to run sql server user defined function when linked two server.
 
I have linked two sql server.There is one function called getenc().This function created on first server.What i want.I wants to run this user defined function on the second sql server. can any one help me?
 
Regards
Jerminxxx

View Replies !
EMERGENCY:rollback Function For Sql Server 2005?
is there a roll back function for sql server 2005 that would change data back to what it was before the execution of last update  query?

View Replies !
Does SQL Server 2005 Has Similar Function Like Mysql_fetch_row ?
I just began to use SQL Server 2005 as database programming and
found out that I have to translate mysql_fetch_row into SQL Server 2005
but I cannot find some related functions/api, and I was wondering
Does SQL Server 2005 has similar function like mysql_fetch_row ?
Or if not, any advice how I can program to acheive similar functions ?
thank you in advance.

View Replies !
How To Determine, Inside A Function, If A Linked-server-query Returned Results
Hi, have configured an ODBC linked server for an Adaptive Server Anywhere (ASA6.0) database.
I have to write a function (not a procedure) that receives a number (@Code) and returns 1 if it was found on a table in the linked server, or 0 if not. Looks very simple...
One problem, is that the queries on a linked-server must be made through the OPENQUERY statement, which doesen't support dynamic parameters. I've solved this making the whole query a string, and executing it, something like this:

SET @SQL='SELECT * FROM OPENQUERY(CAT_ASA, ''SELECT code FROM countries WHERE code=' + @Code + ''')'
EXEC sp_executesql @SQL

(CAT_ASA is the linked-server's name)

Then, i would use @@ROWCOUNT to determine if the code exists or not. But before this, a problem appears: sp_executesql is not allowed within a function (only extended procedures are allowed).
Does somebody know how to make what i want?? I prefer to avoid using temporary tables.
Thanks!

View Replies !
How To Create Assembly Function Using Dll Files In SQL Server 2005???
Hiiiiiiii all
 
I have to make a user defined function in c# as the class liberary and create a dll file, now i want to use this function in SQL Server 2005 as a part of CLR Integration
 
I have tried like this
 

CREATE ASSEMBLY abc
FROM 'C:abc.dll'

WITH PERMISSION_SET = SAFE
 
but it gives me
incorrect syntax error 
so plzzzzz anyone help me wht to do in my probbbbbbbbb???????
 
Pratik Kansara

View Replies !
How To Read CSV File In SQL Server 2005 Using OpenRowSet Function
Hi

i want to access a CSV file using OpenRowSet function in SQL Server 2005.

 

Anyone having any idea; would be of great help.

Regards,

Salman Shehbaz.

View Replies !
SQL Server Date Format Query
Dear All,

I'm having a query problem regarding to the date format. From a table, there's a record of patients' birthdate.

In order to identify their age, how should i perform the query?

Select * from patient where BirthDate.Year < 1950

I've tried the above query where i want to extract patients' records who born before 1950, however, it generates error. Can somebody help?

M i K e

View Replies !
SQL Server 2005 SELECT MAX Function For Multiple Columns On The Same Record
Hello,
 
I am trying to figure out how to use the select maximum command in SQL Server 2005.  I have already created a database and I have it populate it with multiple fields and multiple records.  I Would like to create a new column or field which contains the maximum value from four of the fields.  I have already created a column and I am trying to figure out how to use a command or SQL statement which is entered into the computed equation or formula in the properties for this field/column. 
 
Any help you can provide will be greatly appreciated!
 
Thank you,
Nathan

View Replies !
ODBC Link From Access To SQL Server 2005 Stored Function
If I define a table-valued function in a SQL Server 2005 database, can I link to it from Access 2003 using ODBC?

I've defined the function successfully, and I can link from Access to tables in the database (so my ODBC link is basically functioning), but I can't see the table-valued function in the Linked Table Manager in Access.

I can define a pass-through query to grab the table, but with a pass-through query I have to provide the ODBC password every time.

What am I missing?

Suggestions?

View Replies !
Date Function In C#
hi experts,
i'm working in a web page for some statistics and i have a calendar where the customer can choose a day a week or a month and according to the date he select i need to query the database according to the date selected.
what i want to know is how can i store the date for a day in a variable so i can call it from a stored procedure, the day actually is easy what i want is how can i store the whole week in a variable so i can give it to the stored procedure and query the data in the database according to the whole week may be with startday and endday
also the same problem for the whole month, any idea how can i implement that in C#?!!!
thanks

View Replies !
Date Function
Hi!I have a report that needs to be run on the seventh of every month forthe dates from 6th of the previous months to the 5th of the currentmonth. For example, I have to run a report on February 7th for the01/06/2007 to 02/05/2007. Right now I am doing it manually but I wascurious if there a function or something that will give me therequired date range on the 7th of every month.Any ideas?Thanks,T.

View Replies !
Date() Function And SQL
I am running a query using the MS Query Analyzer. I am inserting a large number of fields into a table, one of the fields is a date field where I enter the date (Hard Coded) that the query is run. I was wondering if it was possible to have the script get the date while it is running via the Date() function. I have tried the following:


Declare @DateVar SmallDateTime
Set @DateVar = Date()


I am getting an error on the second line, so I guess the Date() function is not native to SQL. So is there another way of accomplishing this?


Thanks

View Replies !
Date Function
Is it possible to retrive the number of days between two dates.

I'm aware of the DateDiff function but I can't figure out how to calculate the number days between two columns containing dates in a table.

All help is welcome

Regrads OIS

View Replies !
Date Function
I am working with crystal report and i need to change the date format, i can't do it with the tabs because the date is in string, what is the sytax to change it?

{calllog.callstatus} = "Open" and
{Calllog.Priority} = "1" and
{Asgnmnt.Dateassign} <= "2000-5-17

and i want to change the date to mm-dd-yy

Thanks

View Replies !
Date Function
Came across this really cool script that Rust Hansen wrote.Ran it and it works beautifully. What happens when you want this function to work on all dates ? what l mean is currently you would do the select in the following format:

select dbo.FormatDate('9/21/2001','dddd, mmmm d1, yyyy')
from affordability
what if l want dates between or all dates in that table how would one write the select statement?

What if you want to declare a variable and pass on the value of the formatted date?

Well l know l ask too many questions but thanks to the sql boffins out there who always give helpful and clever hints.


/*
//////////////////////////////////////////////////////////////////////////////////
Author: Rusty Hansen 8-21-2001
Description: Formats a date to a specific format.
Parameters:
@dDate = A value or field of datatype datetime or a value or field that can be explicitly converted to
a datetime datatype.
@sFormat varchar(40) = Format codes using the characters described below

MMMM or DDDD = the full name for the day or month
MMM or DDD = the first 3 letters of the month or day
MM or DD = the two digit code signifying the month or day
M1 or D1 = the month or day value without a preceding zero
YYYY = a four digit year
YY = a two digit year

All other characters will not be replaced such as / - . * # a b z x % and will show
up in the date in the same relative position that they appear in the format
parameter.

Examples
select dbo.FormatDate('9/21/2001','dddd, mmmm d1, yyyy') --> Friday, September 21, 2001
select dbo.FormatDate('9/21/2001','mm/dd/yyyy') --> 09/21/2001
select dbo.FormatDate('9/21/2001','mm-dd-yyyy') --> 09/21/2001
select dbo.FormatDate('9/21/2001','yyyymmdd') --> 20010921
select dbo.FormatDate('9/5/2001','m1/d1/yy') --> 9/5/01
select dbo.FormatDate('9/21/2001','mmm-yyyy') --> Sep-2001

//////////////////////////////////////////////////////////////////////////////////
*/

create function [dbo].[FormatDate]
(
@dDate datetime --Date value to be formatted
,@sFormat varchar(40) --Format for date value
)
returns varchar(40)
as
begin

-- Insert the Month
-- ~~~~~~~~~~~~~~~~
set @sFormat = replace(@sFormat,'MMMM',datename(month,@dDate))
set @sFormat = replace(@sFormat,'MMM',convert(char(3),datename(mo nth,@dDate)))
set @sFormat = replace(@sFormat,'MM',right(convert(char(4),@dDate ,12),2))
set @sFormat = replace(@sFormat,'M1',convert(varchar(2),convert(i nt,right(convert(char(4),@dDate,12),2))))

-- Insert the Day
-- ~~~~~~~~~~~~~~
set @sFormat = replace(@sFormat,'DDDD',datename(weekday,@dDate))
set @sFormat = replace(@sFormat,'DDD',convert(char(3),datename(we ekday,@dDate)))
set @sFormat = replace(@sFormat,'DD',right(convert(char(6),@dDate ,12),2))
set @sFormat = replace(@sFormat,'D1',convert(varchar(2),convert(i nt,right(convert(char(6),@dDate,12),2))))

-- Insert the Year
-- ~~~~~~~~~~~~~~~
set @sFormat = replace(@sFormat,'YYYY',convert(char(4),@dDate,112 ))
set @sFormat = replace(@sFormat,'YY',convert(char(2),@dDate,12))

-- Return the function's value
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
return @sFormat
end

View Replies !
DATE FUNCTION
Is there any function avaibale that separates the DATE and TIME from one column having DATETIME in the following format:

2002-02-02 07:33:59.000


Any suggestion is highly appreciated.

Viv

View Replies !
Date Function.
I need to format the getdate() function in SQL to return only the date and year and not the timestamp.

View Replies !
DATE FUNCTION
i have just started working on SQL and i am trying to solve this puzzle maybe smoe one could do it.. i have to make a query such that
it will take all the transactions throughout the day sort them with the accnt number and then give total amount in the transaction, also the total amount should be > 10000 if some one can try and locate the problem with hte logic i would appreciate it..

just for instance what i did was i tried using the convert in group by and then sum(deposit) this doesnt work.. i am really confused please help.

i have written this query:

declare @datelastweek as datetime
declare @yesterday as datetime
declare @date as datetime
set @Date = Convert(varchar,GetDate() - 1,1)
SET @datelastweek = DATEADD(Day, 1, (DATEADD(Week, -1, @Date)))
SET @yesterday = dateadd(day,1,(dateadd(day,-1,@date)))


select accountno, sum(amount), convert (varchar, TransactionTime -1,1)
from deposit tb join transaction t on tb.id=t.id
where TxnTime between @datelastweek and @date
group by DATEADD(d,DATEDIFF(d,0,TxnTime),0),t.Accountno, txntime
having sum(tb.amount)>10000

Rahul

View Replies !
Date Function
I need to sort some data by date: my date format is looks like this
5/7/2007 11:38:54 AM. but i need to sort sort by just the first part "5/7/2007" how do i achieve this.?

Melvin Felicien
IT Manager
DCG Properties Limited

View Replies !
Date Function
Dear Experts,
Actually, ineed a function to display wether the given date is working day or not............

id the given date is a sunday or saturday, then it should display like...holiday.
or else it should say working day..

please help me in this regard.......
one more thing, if the given date is sunday, then it should give the previous sunday date (minus seven days)

thank you in advance......

I'm trying with this function

CREATE FUNCTION ISOweek (@DATE datetime)
RETURNS int
AS
BEGIN
DECLARE @ISOweek int
SET @ISOweek= DATEPART(wk,@DATE)+1
-DATEPART(wk,CAST(DATEPART(yy,@DATE) as CHAR(4))+'0104')
--Special cases: Jan 1-3 may belong to the previous year
IF (@ISOweek=0)
SET @ISOweek=dbo.ISOweek(CAST(DATEPART(yy,@DATE)-1
AS CHAR(4))+'12'+ CAST(24+DATEPART(DAY,@DATE) AS CHAR(2)))+1
--Special case: Dec 29-31 may belong to the next year
IF ((DATEPART(mm,@DATE)=12) AND
((DATEPART(dd,@DATE)-DATEPART(dw,@DATE))>= 28))
SET @ISOweek=1
RETURN(@ISOweek)
END


Vinod

View Replies !
DATE FUNCTION
HOW TO CONVERT THE VALUES IN DATETIME COLUMN FOR EX

2006-03-17 03:56:00.000
TO
2006-03-17 00:00:00.000

I HAVE TO COMPARE ONLY DATE TO EXTRACT REPORTS.

THANKS IN ADV

View Replies !
Date() Function
Hi all, it's me again.

I'm trying to implement a query that will show all records from three months prior to a certain date (that the user will input) and that date.

This is what I wrote:

SELECT Transactions.Date, Transactions.Details,
FROM Transactions
WHERE Transactions.DATE Between [Forms]![FormNAME]![Date] And DateAdd("M",-3,[Forms]![FormNAME]![Date]);


The idea is that the user is presented with a form which has a single text box to input the date. Then he/she clicks a button (which runs the above query) and the list is presented.

However, when I try to run it, I get back ALL records before a certain date...not just for the three months prior to it.


What am I doing wrong?

View Replies !
Date Function
I'm trying to create a function that takes a DATETIME field and adds 30 days to it. Does anyone know the syntax for this? Thanks in advance. :)

View Replies !
Date Function
Dear gurus,

How do get Saturdays & sundays in between the given dates.

Thanks in advance

cool...,

View Replies !
Date Function
hai to all,
i need a help ,that if i give the UTCdate as parameter in my stored proc i have to get the output as getdate() likewise if i give the getdate() i have to get the o/p as Getutcdate()


Thanks in Advance

View Replies !
Date Function
i have seen that date function which MVJ has created and its really very useful..

but i m getting error while selecting getdate() as @last_date in that function

SELECT
distinct date FROM
dbo.F_TABLE_DATE('1/1/1999', getdate()) AS Date

error is : Incorrect syntax near 'getdate'

what's mistake?

can anyone help me?

thanks in advance.

View Replies !
Problem With The Date Function
How to calculate the exact date before certain number of days.Say for example want to get the date 50 days before today's date.Thanks

View Replies !
Date Function In DTS Package
How can I make this work against an Access table through an ODBC dsn in my DTS package? I need to subtract 1 day from the current date.

Tried this, which is incomplete of course, (need to subtract the 1 day):
WHERE (TTDateTimeIn >= DATEDIFF(dd, 1, { fn CURDATE() }))

Got this error:
[Microsoft][ODBC Microsoft Access Driver] Too few Parameters. Expected 1.

View Replies !
Function Or SP For Date Conversion
i have a field that date stored in it, format of this date is somethin like timestamp. for example today(9Nov2005) saved as 38665.
how can i convert this value to a normal date format?
any function or sp?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved