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.
Author |
Topic |
avijit111@gmail.com
Yak Posting Veteran
55 Posts |
Posted - 2010-05-04 : 09:48:10
|
Hi all,can it possible to compare with system date and stored table date.Means i am having a table name P21_Pay_History_Detail. the dll given below.CREATE TABLE [dbo].[P21_Pay_History_Detail] ( [C03_Organisation_code] [GLCOMPANY] NOT NULL , [C29_Location_Code] [GLLOCN] NOT NULL , [H01_emp_num] [empnum] NOT NULL , [H10_assignment_no] [tinyint] NOT NULL , [P06_Payroll_code] [PAYROLL] NOT NULL , [P03_Process_Period] [smallint] NOT NULL , [P09_Element_code] [ELMCODE] NOT NULL , [P01_Period_Unit_Code] [PRDUNIT] NULL , [P21_no_of_attend_units] [cmn_Plow] NULL , [P21_Actual_attend_units] [cmn_Plow] NULL , [P21_STD_Rate] [cmn_Pamt] NULL , [P21_Actual_Rate] [cmn_Pamt] NULL , [FS_currency] [GLCURRCODE] NOT NULL , [P21_STD_Rate_Basecur] [cmn_Pamt] NULL , [P21_Actual_Rate_Basecur] [cmn_Pamt] NULL , [P21_Pay_Run_Tag] [char] (1) COLLATE SQL_1xCompat_CP850_CI_AS NULL , [P21_Conversion_Rate] [cmn_Pexch_rate] NULL , [P21_Dummy1] [QCD] NULL , [P21_Dummy2] [QCD] NULL , [User_Id] [smallint] NOT NULL , [Modified_Date] [datetime] NOT NULL , [Time_Stamp] [timestamp] NULL )in the above table i have a field called modified_date. what exactly i would like to say is i want to write one procedure where i want to fetch system date (means current date) and compare with P21_Pay_History_Detail table modified_date.The system date having month part like(dd/mm/yyyy)and modified_date having same as system date like (dd/mm/yyyy).where i want to compare system month part like (mm) with modified_date month part like (mm). because i want to compare the month and fetch data. please if possible then send me the modified procedure . create proc aaa -- EXEC aaa 'gpo','vnr',1, '' --grant all on aaa to public @comp_code char(10),@location char(4) ,emp_code varchar(6)asbegin set nocount on SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [dd/mm/yy] Create table #tmp_ex( @modified_date char(18)) insert into #tmp_ex select @modified_date from P21_Pay_History_Detail where end |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-04 : 12:49:09
|
its possible. so you want all data for current month? then useWHERE modified_date > = DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)AND modified_date < DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
avijit111@gmail.com
Yak Posting Veteran
55 Posts |
Posted - 2010-05-04 : 22:48:06
|
thanks a lots visakhm...i will try and let u know... |
|
|
avijit111@gmail.com
Yak Posting Veteran
55 Posts |
Posted - 2010-05-05 : 01:55:11
|
I tried, can you please send me procedure where system date compare with modified_date from the table...and give the output as how much month in between modified_date and system date...alter proc aaa-- EXEC aaa 'gpo','vnr','02260'--grant all on aaa to public @comp_code char(10),@location char(4) ,@emp_code varchar(6)asbegin set nocount onSELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [dd/mm/yy] Create table #tmp_ex(modified_date char(18))insert into #tmp_exselect modified_date from P21_Pay_History_DetailWHERE modified_date > = DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)AND modified_date < DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)end |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-05 : 02:56:11
|
Your modified_date is a datetime in your ddl so don't convert to varchar. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|
|
|