Forum Replies Created

Viewing 10 posts - 46 through 55 (of 55 total)

  • RE: Pass the NULL value

    1) You have to remove THEN from the IF statement

    2) To assign a value to a variable you have to use SET statement

    So, replace this line

    IF @NewFund_Id = ''...

  • RE: Grouping distinct values by date

    SELECT date,

    SUM(CASE WHEN typesold = 1 THEN 1 ELSE 0 END) AS count_1,

    SUM(CASE WHEN typesold = 2 THEN 1 ELSE 0 END) AS count_2,

    SUM(CASE WHEN typesold...

  • RE: Is this SARGable?

    As Jeff said you are right, the third query is sargable.

    The second query shows exactly how SQL Server rewrites your initail query and it's not SARGable because it always converts...

  • RE: First and last records by reference number

    For the last index you can use ROW_NUMBER function again with a small change in the OVER clause:

    ,row_number() over (

    partition by AD.UnitNumber ,AD.AccountNumber order by AD.VisitID) as [Index]

    ,row_number() over...

  • RE: DateDiff one Date column of First Row and the other Date column of second row.

    Yep, as Sean said I assumed that you use SQL 2012 and windows offset functions are a good choice in situations where you want to refer to some other row...

  • RE: Dates

    You could create a derived column indicating the year and quarter in which a date belongs to. Something like this:

    CAST(YEAR(DateColumn) AS NVARCHAR(4))

    + 'Q' + DATENAME(Quarter, DateColumn) AS YearQuarter

    and then...

  • RE: DateDiff one Date column of First Row and the other Date column of second row.

    Here is a piece of code which calculates if the flag IsDateDiffLess14_Calculation should be set or not.

    SELECT RowID,

    CASE WHEN DATEDIFF(DAY, Date2, LEAD(Date1) OVER(PARTITION BY IDNo ORDER BY RowId)) <...

  • RE: query time question

    If you expect only one row as result then you should create an index on the column participating in the WHERE clause in order to improve performance.

    Indexes in a...

  • RE: cardinality and nchar columns, query problems

    If the column AddressParseStatus comes for the first time in a query as a part of filter SQL Server automatically creates statistics for the column (if AUTO_CREATE_STATISTICS is ON, which...

  • RE: Declared Variable in WHERE clause weird behavior

    In the first execution plan on the Operator Index Seek QueryId_nc you can see that the Estimated Number of Rows is about 4 and Actual Number of Rows is...

Viewing 10 posts - 46 through 55 (of 55 total)