Forum Replies Created

Viewing 15 posts - 76 through 90 (of 1,438 total)

  • Reply To: XQuery - Use column value to display correct node

    As simple as

    cross apply x.XmlDoc.nodes('/assessment/template//question[@key=sql:column("QuestionID")]') AS Form(Question)

    Note the double //

    • This reply was modified 4 years, 10 months ago by  Mark Cowne.
    • This reply was modified 4 years, 10 months ago by  Mark Cowne.
  • Reply To: XQuery - Use column value to display correct node

    Sounds like you want this

    cross apply x.XmlDoc.nodes('/assessment/template/question[@key=sql:column("QuestionID")]') AS Form(Question)

    • This reply was modified 4 years, 10 months ago by  Mark Cowne.
  • Reply To: SQL Server - Avoid cursor while serial update

    Here's a recursive CTE solution

    WITH Recur AS (
     SELECT Person_FROM AS Person_FROM_Start, Person_FROM, Person_To, Kind, Pctg_New, Eff_Date
     FROM #transfers
     UNION ALL
     SELECT ts.Person_FROM_Start, te.Person_FROM, te.Person_To, te.Kind, te.Pctg_New, te.Eff_Date
     FROM Recur ts
     INNER JOIN...
  • Reply To: Xquery help please (XML into SQL table)

    If I understand this correctly, you want only leaf nodes

     


    select s.Id,s.Category,
           x.n.value('local-name(.)','varchar(30)') as LimitDescription,
           x.n.value('./text()[1]','int') as LimitValue
    from @sampledata s
    outer apply s.Restriction.nodes('//*[not(child::*)]') x(n);
  • Reply To: SQL Server Pivot Table on two columns renaming one column

    You'll need a dynamic crosstab

    -- Variables used. 
    DECLARE @sqlQuery     NVARCHAR(MAX) ;
    DECLARE @sqlQuery1     NVARCHAR(MAX) ;
    DECLARE @sqlQuery2     NVARCHAR(MAX) ;
    SELECT @sqlQuery1 = (
    SELECT ',MAX(CASE WHEN RuleName = '''+RuleName+''' THEN RuleValue...
  • Reply To: Weird Float Conversion Result

    I think the issue here is that not all values can by represented by floating point numbers. 0.29 is one of them.

    SELECT cast(0.29 as float) -- shows...
  • Reply To: SQL Server Pivot Table on two columns renaming one column

    Just a simple crosstab should do it

    SELECT Id, GroupName,
           MAX(CASE WHEN RuleName = 'Exclude1' THEN RuleValue END) AS Exclude1,
           MAX(CASE WHEN RuleName = 'Exclude2' THEN RuleValue END)...
  • Reply To: repeating block of records

    Here's a way using recursion, probably not efficient but appears to work with your data.

    WITH recur AS (
    SELECT x1.id AS idstart,
           x1.value AS valuestart,
           x1.id AS idend,
       ...
  • Reply To: split one rows to multiple rows in the table based on the size

    You'll need a numbers/tally table for this. Code below uses a built in one.


    declare @chunk_row_size int = 50;
    select row_number() over(order by t.id,ca.number) as id,
           case when (ca.number+1)*@chunk_row_size...
  • Viewing 15 posts - 76 through 90 (of 1,438 total)