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

Regex: Stripping Unwanted Chararcters

by ssi 10. June 2016 07:51
public static string StripLeadingZeros(string sAlphaNumberText)
       {
           /*
            * That will trim trailing zeros if they appear after the period in a decimal number (it will always leave a single zero).
            *  It also accounts for numbers that appear at the very end.
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText,
                        @"(?<=\.\d+?)0+(?=\D|$)",
                        String.Empty);
           return sRet;
       }
 
       public static string StripWhitespace(string sAlphaNumberText)
       {
           /*
            * sStrip Whitespace
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, @"\s+""");
           return sRet;
       }
       public static string StripAllButNumbers(string sAlphaNumberText)
       {
           /*
            * strip all characters except numbers
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, @"[^\d]"String.Empty);
           return sRet;
       }
       public static string StripNumbers(string sAlphaNumberText)
       {
           /*
            * sStrip Numbers
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, @"[\d-]"string.Empty);
           return sRet;
       }
 
       public static string StripAllSpecialCharacters(string sAlphaNumberText)
       {
           /*
            * Strip All Special Characters
            */
           string sRet = "";
 
           sRet = Regex.Replace(sAlphaNumberText, "[^0-9a-zA-Z]+""");
           return sRet;
       }

Tags: , , ,

Blog | CSharp | Regex

SQL Query with Detail Record and Subtotal Record

by ssi 22. February 2016 08:04

WITH Vals AS (

   SELECT [STATE]

      ,[Fname]

      ,[Lname]

      ,[EMAIL]

      , 1 DisplayOrder

      , 1 as Name_Count

       FROM  [ssi_tbl_NameAddress]

        UNION ALL   

        SELECT  [STATE] 

                ,'' AS Fname 

                ,'' AS lname

                ,'' as email  

                ,2 DisplayOrder

                , count(*) as Name_Count

        FROM    [ssi_tbl_NameAddress]

        GROUP BY [STATE]

)

SELECT [STATE]

      ,[Fname]

      ,[Lname]

      ,[EMAIL]

      ,Name_Count

FROM    Vals

ORDER BY  [STATE],DisplayOrder

 

with  sum()

DECLARE @Sales TABLE(

        CUS_ID  INT,

        PRODUCT VARCHAR(20),

        AMOUNT FLOAT

)

INSERT INTO @Sales SELECT 12,'A', 2.50 

INSERT INTO @Sales SELECT 12,'B', 5.80 

INSERT INTO @Sales SELECT 24,'A', 10.00 

INSERT INTO @Sales SELECT 24,'B', 30.00

 

;WITH Vals AS (

        SELECT  cus_id, 

                product, 

                amount,

                1 DisplayOrder,

                SUM(amount) OVER(PARTITION BY cus_id) OrderTotal

        FROM    @Sales 

        UNION ALL   

        SELECT  cus_id, 

                'Total' AS product, 

                SUM(amount),

                2 DisplayOrder,

                SUM(amount)

        FROM    @Sales 

        GROUP BY cus_id

)

SELECT  cus_id,

        product,

        amount

FROM    Vals

ORDER BY  OrderTotal DESC,cus_id,DisplayOrder, product 

 

 

Tags: , ,

SQL

SQL:Remove Duplicates

by ssi 21. February 2016 12:05

DELETE FROM [ssi_tbl_NameAddress]

WHERE  control NOT IN (SELECT MAX(control)

                  FROM   [ssi_tbl_NameAddress]

                  GROUP  BY Lname,fname 

                  /*Even if ID is not null-able SQL Server treats MAX(ID) as potentially

                    nullable. Because of semantics of NOT IN (NULL) including the clause

                    below can simplify the plan*/

                  HAVING MAX(control) IS NOT NULL) 

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

A SQL query walks into a bar

by ssi 1. February 2016 16:14

A SQL query walks into a bar. He approaches two tables and says, Mind if I join you?

Tags: ,

SQL

Software Release

by ssi 19. January 2016 09:55

Tags:

CSharp

EWS Managed API 2.0

by ssi 13. January 2016 10:06

 

https://msdn.microsoft.com/en-us/library/office/dd633709.aspx

Applies to: EWS Managed API

The Exchange Web Services (EWS) Managed API provides a simple and full-featured interface for developing and extending applications that use EWS. You can use the EWS Managed API to access EWS in versions of Exchange starting with Exchange Server 2007 Service Pack 1 (SP1), including Exchange Online.

The EWS Managed API provides user-friendly abstractions of XML messages, XML serialization, and the formation of the HTTP requests and responses that are sent between the client and server.

You can download the EWS Managed API from the Microsoft Download Center.

Tags:

CSharp

Timespan Start Stop Clock

by ssi 13. January 2016 09:48
DateTime dStopCLock = DateTime.Now;
TimeSpan ts = dStartCLock - dStopCLock;
double differenceInSeconds = ts.TotalSeconds;
ts = TimeSpan.FromSeconds(ts.TotalSeconds);
 
string sDuration = string.Format("Dur: {0:D2}h:{1:D2}m:{2:D2}s",
             ts.Hours,
             ts.Minutes,
             ts.Seconds);
Console.WriteLine(sDuration);

Tags:

CSharp

Calendar

<<  April 2024  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

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

""All glory is fleeting.""
General George S. Patton, Jr