Forum Replies Created

Viewing 15 posts - 766 through 780 (of 1,228 total)

  • RE: Split the values from ('1,2,3,4') to ('1','2','3','4') or (1,2,3,4)

    Narud (12/14/2011)


    You can create a function like this that returns the values in a table:

    <<snip>>

    And use it in this ways

    SELECT Value FROM dbo.fString2Table('1,2,3,4,5', ',')

    Or

    SELECT Value FROM dbo.fString2Table('1,2,3,4,5', ',')

    ...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: How to return 0 if not exists, or the result if exists?

    boeledi (12/14/2011)


    I finally found the solution...

    Simply use the following:

    SELECT COALESCE(( sqlstatement), 0)

    For example

    SELECT A.*, Score = 100 * ( SELECT COALESCE( ( SELECT ftt.RANK FROM tbl_description TD INNER...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: How to return 0 if not exists, or the result if exists?

    Have you tried APPLY?

    SELECT A.*, x.Score

    FROM tbl_owners A

    OUTER APPLY (

    SELECT Score = ftt.[RANK]

    FROM tbl_description TD

    INNER JOIN CONTAINSTABLE(dbo.tbl_description, [description], @freetext_keywords) AS ftt

    ON TD.description_id = ftt.

    WHERE TD.owner_id = A.owner_id

    ) x

    WHERE

    {{my conditions}}


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: How to group based on value and rank

    DROP TABLE #Sample

    CREATE TABLE #Sample (avalue INT, adate DATETIME)

    INSERT INTO #Sample (avalue, adate)

    SELECT 5, '01/01/2011 00:00:00' UNION ALL

    SELECT 5, '02/01/2011 00:00:00' UNION ALL

    SELECT 5, '03/01/2011 00:00:00' UNION ALL

    SELECT 10, '04/01/2011...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Optimazise the Query Performance

    There's some strange date/time arithmetic going on here. If it's fixed, you won't need datetime functions around columns - there are better ways.

    What datatype are the following: @ToDate, @FromDate, SP.InTime,...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Advice on how to return results by matching score

    Sean Lange (12/13/2011)


    Can you put together some ddl and sample data? It sure make life a lot easier without having to create your structures and data. 😉

    A list of the...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Pivot Table Headache

    ;WITH Preaggregate AS (

    SELECT

    Category,

    [MonthEntered]= DATENAME(month,DateEntered),

    [TotYes]= SUM(CASE WHEN Answer = 1 THEN 1 ELSE 0 END),

    [TotNo]= SUM(CASE WHEN Answer = 0 THEN 1 ELSE 0 END)

    FROM PublicSurvey s

    GROUP...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Split the values from ('1,2,3,4') to ('1','2','3','4') or (1,2,3,4)

    sami.sqldba (12/13/2011)


    DECLARE @NUMBER VARCHAR(50)

    DECLARE @FINAL VARCHAR(50)

    SET @NUMBER = '1,2,3,4,5'

    SET @FINAL = '''' + REPLACE (@NUMBER,',', ''',''') + ''''

    SELECT @FINAL

    How might this work?

    DECLARE @NUMBER VARCHAR(50)

    DECLARE @FINAL VARCHAR(50)

    SET @NUMBER = '1,2,3,4,5'

    SET @FINAL...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Converting to last minute of a month

    Quick today, Koen :hehe:


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Converting to last minute of a month

    duggal.priyanka06 (12/13/2011)


    Hi,

    I have the following query where @User::Cob_Dt is a variable giving me the previous business day.The

    following gives me day of a month i.e. 2011-12-31 00:00:00.000

    declare @cob_dt...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Need help with calculation

    Jeff Moden and others have conducted extensive research into running totals using existing versions of SQL Server, the results of which are published here[/url]. Denali offers a completely new and...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Need TSQL Suggestions to Optimize this Query....

    sql_jr (12/13/2011)


    Thanks!! I have an issue with this part you added:

    inner join dbo.people p with(nolock)

    on r.people_id = p.people_id

    You'd think...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Need TSQL Suggestions to Optimize this Query....

    Hi Dev, yes I do. There's a good reason - if a project here takes a while to resolve, and some take hours or even days, it wouldn't look good...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Need TSQL Suggestions to Optimize this Query....

    First thing I'd do is get the correlated subquery out of the result set and into the FROM list to ensure that it's not being run once for every row...


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • RE: Need TSQL Suggestions to Optimize this Query....

    Can you post the actual plan rather than the estimated plan?


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

Viewing 15 posts - 766 through 780 (of 1,228 total)