Forum Replies Created

Viewing 15 posts - 2,626 through 2,640 (of 4,087 total)

  • RE: Query calculation over a partition

    SELECT *, CAST(COUNT(sales) OVER(PARTITION BY e.customerId) AS BIT)

    FROM #example e

    Drew

  • RE: SQL Date column issues in query

    dogramone (5/26/2016)


    Try running with the variable dates in dd-mon=ccyy format to help with debugging, ie '01 jan 1900

    Do not EVER do this. I believe that there are only two...

  • RE: SQL Date column issues in query

    You're setting your @startdate twice, so the @enddate is NULL.

    Drew

  • RE: Foreach loop File Not Found in SQL Server 2014, but found in Visual Studio 2012

    Setting Up Your SQL Server Agent Correctly.[/url] Especially pay attention to the section What service account to use.

    Drew

  • RE: Large strings

    Jacob Wilkins (5/26/2016)


    drew.allen (5/26/2016)


    Well, the documentation for nchar and nvarchar still says that the the value can be any number from 1 to 4000 or max, and 5000 is clearly...

  • RE: Large strings

    Well, the documentation for nchar and nvarchar still says that the the value can be any number from 1 to 4000 or max, and 5000 is clearly not in that...

  • RE: Foreach loop File Not Found in SQL Server 2014, but found in Visual Studio 2012

    Not the creator name, the account the job is running under. If I remember correctly, by default, this is a SQL account which HAS NO ACCESS TO NETWORK DRIVES....

  • RE: Joining two table based on length of field

    Lowell (5/26/2016)


    something like this gets the desired code name, but which would you want with multiple matches?

    SELECT row_number() over(partition By T2.code_name ORDER BY T2.code) AS RW,T2.code_name As DesiredCodeName,T1.*

    FROM dbo.table1 T1

    ...

  • RE: Computed Column that can be edit

    John Mitchell-245523 (5/26/2016)


    DesNorton (5/25/2016)


    If you need an editable "computed column" ...

    Create a standard column [NICKNAME]

    Create an INSERT trigger that sets [NICKNAME] = [LASTNAME] + ' ' + [FIRSTNAME]

    Then the column...

  • RE: "Duplicate" records - How to coalesce?

    Sturev (5/25/2016)


    drew.allen (5/25/2016)


    Here is another approach. This has the advantage that it accounts for orphaned records.

    Drew

    Thanks Drew! In this case we don't want the orphans; I know, not ideal...

  • RE: Pivot Question

    Also, the reason that you are getting NULLs is that the following code is looking for cases where the CompanyName field is equal to the literal strings 'CompanyPrevName1' and 'CompanyPrevName2'....

  • RE: Pivot Question

    Try the following:

    ; WITH chi_nm AS (

    SELECT *, ROW_NUMBER() OVER(PARTITION BY chi.CompanyID, LEFT(chi.PreviousCompanyName, 3) ORDER BY chi.NameYear DESC) AS rn

    FROM (

    VALUES

    (1,'Kay Enterprises',2015),

    (1,'The Kay INC',2014),

    (1,'Kay INC',2013),

    (1,'Kay Group',2012),

    (2,'RIDGE',2015),

    (2,'The RIDGE PARTNERS',2014),

    (2,'Medical Company of...

  • RE: "Duplicate" records - How to coalesce?

    Here is another approach. This has the advantage that it accounts for orphaned records.

    SELECT

    ROW_NUMBER() OVER(ORDER BY a1.AFFILIATIONID) NewRecordID,

    a1.ENTITYID AS FromRecordID,

    a2.ENTITYID ToRecordID

    FROM #a a1

    LEFT OUTER JOIN #a a2

    ON a1.AFFILIATIONID =...

  • RE: aggregate for previous year specific date

    I believe the following will work in SQL2008. I don't have a SQL2008 test environment handy to test.

    ;

    WITH pd AS (

    SELECT

    pd.PatientNumber,

    pd.DCDispCode,

    pd.DCDate,

    MAX(CASE WHEN pd.DCDispCode = '20' THEN pd.DCDate END) OVER(PARTITION...

  • RE: Are the posted questions getting worse?

    Brandie Tarvin (5/24/2016)


    So today I learned that it is possible to create an infinite loop in SQL. With a CURSOR no less.

    What an interesting day it's been already. @=)

    Apparently FETCH...

Viewing 15 posts - 2,626 through 2,640 (of 4,087 total)