Forum Replies Created

Viewing 15 posts - 376 through 390 (of 1,439 total)

  • RE: How to track table schema changes

    Try using a database trigger

    CREATE trigger mytrigger on database for create_table,alter_table,drop_table

    AS

    ...

  • RE: MERGE Statement assistance

    Both INSERT and UPDATE support the OUTPUT clause

    UPDATE Target

    SET Target.AlphaValue = Source.AlphaValue, Target.NumericValue = Source.NumericValue

    OUTPUT inserted.*, deleted.*

    FROM TargetDB.dbo.AdmFormData AS Target

    INNER JOIN SourceDB.dbo.AdmFormData AS Source ON (Target.FormType = Source.FormType and Target.KeyField...

  • RE: MERGE Statement assistance

    Use a separate INSERT and UPDATE statement, something like this

    UPDATE Target

    SET Target.AlphaValue = Source.AlphaValue, Target.NumericValue = Source.NumericValue

    FROM TargetDB.dbo.AdmFormData AS Target

    INNER JOIN SourceDB.dbo.AdmFormData AS Source ON (Target.FormType = Source.FormType and Target.KeyField...

  • RE: MERGE Statement assistance

    I get a different error message

    The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.

    Try this instead

    MERGE dbo.AdmFormData AS Target

    USING dbo.AdmFormData AS...

  • RE: Update table using Group By

    Something like this??

    DECLARE @t TABLE(DeliveryDate DATE,Assigned INT,Unassigned INT, Total INT)

    INSERT INTO @t(DeliveryDate,Assigned,Unassigned)

    VALUES

    ('2013-04-29',1,0),

    ('2013-04-29',1,1),

    ('2013-04-29',1,1),

    ('2013-04-29',1,1),

    ('2013-04-30',0,0),

    ('2013-04-30',0,1),

    ('2013-05-01',0,0);

    SELECT DeliveryDate,Assigned,Unassigned,

    SUM(Assigned + Unassigned) OVER(PARTITION BY DeliveryDate) Total

    FROM @t

    ORDER BY DeliveryDate

  • RE: XML Question (?)

    SELECT

    (SELECT 'Field1' AS "@name", Field1 AS "text()" FOR XML PATH('ColumnValue'),TYPE),

    (SELECT 'Field2' AS "@name", Field2 AS "text()" FOR XML PATH('ColumnValue'),TYPE),

    (SELECT 'Field3'...

  • RE: TOP 25% rows by Weightage

    If you're using SQL Server 2012, you can do this

    ;with Data(ClassID, MemberID, Weight) as

    (

    select 'A', 1, 10 union all

    select 'A', 2, 20 union all

    select 'A', 3, 40 union all

    select 'A',...

  • RE: Filtering results from SELECT on XML column

    Also this

    SELECT child.value('(parent::node()/ID/text())[1]', 'NVARCHAR(50)') AS [ID]

    , child.value('(State/text())[1]', 'NVARCHAR(50)') AS [State]

    , child.value('(Value/text())[1]', 'NVARCHAR(50)') AS [Value]

    FROM [XmlTable]...

  • RE: Replace .TIF with .pdf

    2Tall (4/12/2013)


    OK, it looks like I was over thinking it.

    [Code]

    UPDATE Documents

    SET DocumentFileName = REPLACE(DocumentFileName,'TIF','pdf')

    WHERE DocumentFileName LIKE '%.TIF' AND DocumentLinked = '1'

    [/Code]

    Can anyone see any potential issued with above code?

    Kind Regards,

    Phil.

    That...

  • RE: Please tell me how can I write one query to resolve this problem.

    This uses a tally table, probably not very efficient though.

    DECLARE @Plates TABLE(StartPlate INT, StopPlate INT);

    INSERT INTO @Plates(StartPlate, StopPlate)

    VALUES(1,12),(15,23);

    DECLARE @BrokenPlates TABLE(StartPlate INT, StopPlate INT);

    INSERT INTO @BrokenPlates(StartPlate, StopPlate)

    VALUES(3,7),(15,18),(21,22);

    WITH E1(N) AS (

    ...

  • RE: Compare two data sets-- Please help

    Maybe this?

    SELECT d.ID

    FROM DATA d

    LEFT OUTER JOIN NEW_DATA n ON n.CODE = d.CODE AND n.CNAME=d.CNAME

    GROUP BY ID

    HAVING COUNT(*) = COUNT(n.CNAME);

  • RE: Inserting missing records using multiple fields as the key

    Try changing

    INSERT INTO Build_list

    (ContractID, SectionID, ItemID, Qty)

    SELECT...

  • RE: Generate all possible number combinations for a provided list of numbers

    Another one to try

    WITH Numbers(N) AS (

    SELECT N

    FROM ( VALUES(1),(2),(3),(4) ) Numbers(N)),

    Recur(N,Combination) AS (

    SELECT N, CAST(N AS VARCHAR(1000))

    FROM Numbers

    UNION ALL

    SELECT n.N,CAST(r.Combination + ',' + CAST(n.N AS VARCHAR(10)) AS VARCHAR(1000))...

  • RE: Get summary of column values from a result set

    You can do this instead, although I don't think it will make much difference

    WITH Results AS (

    SELECT CustomerName, PostalCode

    FROM @CustomerOffices

    WHERE OfficeId BETWEEN @FromOfficeId AND @ToOfficeId)

    SELECT 'Summary' as Summary,

    ...

  • RE: Get summary of column values from a result set

    Good job of posting sample data + results. Thanks.

    SELECT 'Summary' as Summary,

    STUFF((SELECT ',' + CustomerName AS "text()"

    FROM @CustomerOffices

    ...

Viewing 15 posts - 376 through 390 (of 1,439 total)