Previous Month, Week

by ssi 27. September 2016 15:48

set@StartDate= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)--First day of previous month

set@EndDate  =DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1) --Last Day of previous month

    end

else

    begin

set@StartDate=dateadd(dd,((datediff(dd,'17530101',getdate())/7)*7)-7,'17530101') -- Date greater than or equal to Monday of last week

set@EndDate  =dateadd(dd,((datediff(dd,'17530101',getdate())/7)*7)-2,'17530101') -- Date before Saturday of last week

Tags: ,

SQL

How to Use a Cursor in SQL

by ssi 11. February 2016 09:32

USE [LENDER_LOAN_SERVICE]
GO

/****** Object:  UserDefinedFunction [dbo].[uf_ssi_GetHMDARaceString]    Script Date: 02/11/2016 09:30:40 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE  FUNCTION [dbo].[uf_ssi_GetHMDARaceString]( @LoanID int , @BRW varchar(50))
RETURNS nchar(5)
AS
BEGIN
DECLARE @Event_ID varchar(100)
DECLARE  @Return varchar(500);
 
--set @LoanID ='1344'
DECLARE my_cursor CURSOR FOR
SELECT [_Type] FROM  [HMDA_RACE] where  [loanGeneral_Id] =@LoanID and [BorrowerID] = @BRW
OPEN my_cursor
FETCH NEXT FROM my_cursor
INTO @Event_ID
set  @Return =  ''
--print @Event_ID
WHILE @@FETCH_STATUS = 0
BEGIN
     if @Event_ID = 'AmericanIndianOrAlaskaNative'    set  @Return =   @Return+ '1'
     if @Event_ID =  'Asian'  set  @Return =   @Return+ '2'
     if @Event_ID = 'BlackOrAfricanAmerican' set  @Return =   @Return+ '3'
     if @Event_ID = 'NativeHawaiianOrOtherPacificIslander' set  @Return =   @Return+'4'
     if @Event_ID = 'White' set  @Return =   @Return+'5'
     --else set  @Return =   @Return + '-'
    --print @Event_ID
    --print @Return
    FETCH NEXT FROM my_cursor
    INTO @Event_ID
END
CLOSE my_cursor
DEALLOCATE my_cursor
 if (SELECT [RaceNationalOriginRefusalIndicator] FROM  [GOVERNMENT_MONITORING] where [loanGeneral_Id] =@LoanID and [BorrowerID] = @BRW)=1 set @Return='6'
RETURN substring(@Return+'     ',1,5)

END;


GO


Tags: ,

SQL

First of Current Month/First of Current Month

by ssi 11. February 2016 09:28

--First of Current Month
--First of Current Month
select    DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) as Firstday                                              
    ,dateadd(day, -1, dateadd(month, 1, dateadd(day, 1 - day(GETDATE()), GETDATE()))) as lastday

Tags: ,

CSharp | SQL

Calendar

<<  May 2024  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"A woman's guess is much more accurate than a man's certainty."
Rudyard Kipling