Forum Replies Created

Viewing 15 posts - 3,436 through 3,450 (of 3,957 total)

  • RE: Insert into two different tables

    You can try this:

    IF OBJECT_ID('TempDB..#mytable1','U') IS NOT NULL

    DROP TABLE #mytable1

    CREATE TABLE #mytable1

    (ID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,

    COMPANY NVARCHAR(50),

    CAT NVARCHAR(50))

    IF OBJECT_ID('TempDB..#mytable2','U') IS NOT NULL

    DROP TABLE #mytable2

    CREATE TABLE #mytable2

    (ID INT IDENTITY(1,1) PRIMARY...

  • RE: Extract related values recursively

    Here is the recursive solution but I'm not sure why you'd want to use it.

    DECLARE @s-2 TABLE (salesinvoiceid CHAR(1), salesreceiptid CHAR(2))

    INSERT INTO @s-2

    SELECT 'a','A1' UNION ALL SELECT 'a','B1' UNION ALL...

  • RE: Subtract Value At Previous Row From Current Row

    So I give you the link for gaps and islands and can't figure out how to make it work myself! What's up with that?!

    So I am left with something...

  • RE: How to do math job with this two table?

    Jeff is right, but if you can't change to do what he's saying, then you can also do it this way.

    CREATE TABLE #TABLEA (Name VARCHAR(3), [201202] INT, [201203] INT, [201204]...

  • RE: Subtract Value At Previous Row From Current Row

    Looks like a slightly more complicated version of a gaps and islands type problem.

    You may want to take a look at this link and see if it helps you.

    http://www.sqlservercentral.com/articles/T-SQL/71550/

  • RE: Calculate weeks for past months

    ColdCoffee (6/10/2012)


    OP needs it to be pivoted, Dwain 🙂

    I didn't interpret it that way but you may be right.

  • RE: Calculate weeks for past months

    How about something like this?

    DECLARE @InputDate DATETIME

    ,@DesiredDay VARCHAR(9)

    SET @InputDate = '2012-05-18'

    SET @DesiredDay = 'Friday'

    ;WITH Tally AS (

    SELECT TOP 65

    ...

  • RE: xml Question

    Some Dynamic SQL may be your friend here. Notice that I've made this work for the column of a table.

    CREATE TABLE #t (MyXML XML)

    INSERT INTO #t

    SELECT '<item>

    ...

  • RE: xml Question

    Michael Kaluza (6/8/2012)


    My bad I didn't make myself clear enough. In the extraAttributes table I have over 130 distinct attribute_names (I just used 'COLOR' and 'SIZE' as examples) and...

  • RE: wHICH MODEL IS BEST?

    Lynn Pettis (5/18/2012)


    MODEL 01:

    name email A B C D

    aa john@test.com 0 0 1 1

    bb rick@test.com 0 1 0 1

    cc sally@test.com 0 1 1 0

    dd aha@test.com 1 1 0 0

    What...

  • RE: need help to simplify this script

    ChrisM@Work (6/8/2012)


    dwain.c (6/5/2012)


    Just to show that I'm keeping current on SQL 2008 stuff, and probably for no other reason, I thought I'd post a less verbose alternative.

    SELECT Employee, NEW_LOB, NEW_DEPARTMENT,...

  • RE: isnumeric() ?

    You might want to select out all the rows based on a PATINDEX that allows only numerics. Then you can examine what's actually in the data and what might...

  • RE: SQL script

    You're welcome.

    Be aware that you may want to consider dropping the first '%' if you don't need to consider any prefix for the number.

  • RE: xml Question

    Yup.

    DECLARE @MyXML XML

    SET @MyXML = '

    <item>

    <attribute_name>COLOR</attribute_name>

    <attribute_value>Black</attribute_value>

    </item><item>

    <attribute_name>SIZE</attribute_name>

    <attribute_value>S</attribute_value>

    </item><item>

    <attribute_name>SIZE</attribute_name>

    <attribute_value>L</attribute_value>

    </item>'

    SELECT...

  • RE: SQL script

    You didn't say what to do with duplicates, so this solution returns them:

    DECLARE @t1 TABLE (Name VARCHAR(2), Number VARCHAR(10))

    DECLARE @t2 TABLE (Number VARCHAR(10))

    INSERT INTO @t1

    SELECT 'X1','12345' UNION ALL SELECT 'X2','145896'

    UNION...

Viewing 15 posts - 3,436 through 3,450 (of 3,957 total)