Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Suggestion Needed at query with dates

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2007-01-09 : 10:44:54
hi,
i have a table in which i am storing dates in one column. the datatype for my column is datetime. i inserted some details for date say '02/01/2006'(mm/dd/yyyy) fromat. here again i am trying to insert some datails with some requirements.
requirement 1: i should include the details in same month for which i included earlier means i shouldn't include details for month 02, because i have included details for same month alredy.

so inorder to acheive this i tryed in this way,
i tryed to read the month from record 02/01/2006 by a sql query, but i was failed to acheive it. can u give me query for this or suggest another solution
i need to include five members data for same day and once i include for a particular month i cannot include details for same month for same members.
pls suggest me a query or a solution



One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-09 : 11:00:00
If you are not using ISO date format (universal date format) remember to
SET DATEFORMAT { DMY | MDY }

select * from <yourtablenamehere>
where <yourcolumnnamehere> < dateadd(month, datediff(month, 0, getdate(), 0)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-09 : 11:04:32
[code]IF Exists(select * from Tbl where MemberID = @MemberID and convert(varchar(6), datecol, 112) = convert(varchar(6),@dateparam, 112)
-- Raise error here
Else
-- Insert code goes here[/code]

Here I assume that you are passing current date as datetime parameter.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -