Forum Replies Created

Viewing 15 posts - 706 through 720 (of 1,082 total)

  • RE: swap data between 3 fields?

    Do you really mean 92 Fields? or do you mean Rows?

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: swap data between 3 fields?

    HI there,

    Try this:

    DECLARE @mytable TABLE

    (date DATETIME,

    Field1 VARCHAR(10),

    Field2 VARCHAR(10),

    Field3 VARCHAR(10),

    Field4 VARCHAR(10),

    Field5 VARCHAR(10),

    Field6 VARCHAR(10))

    INSERT INTO @mytable

    SELECT '2008/08/28','jim','Dave','jim','jim','Dave','Dave' UNION

    SELECT '2008/08/29','Dave','Jim','Jim','Jim','Dave','Dave'

    SELECT *

    FROM @mytable

    UPDATE @mytable

    SET

    Field1 = CASE Field1 WHEN 'Jim' THEN 'Dave' WHEN...

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: assigning variables during query processing

    So you want to assign and return the value?

    Or do you simple want to assign and use it again to calculate other variables?

    If so then simply doing this will take...

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: assigning variables during query processing

    HI there,

    Sorry about this, but I'm not 100% sure what you trying to do!

    Could you give me an input output example so that I can try and help?

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: convert different rows ( dynamic no.of rows ) into different columns

    ooops sorry got ahead of myself

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: convert different rows ( dynamic no.of rows ) into different columns

    I noticed that your two solutions don't work if there is a dupicate row, so I'm not sure if that situation will actually occur or not.

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: convert different rows ( dynamic no.of rows ) into different columns

    HI All,

    Not all of the solutions seem to work.

    I was going to do some performance testing and noticed that not all of them work.

    Here is the code for all the...

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: convert different rows ( dynamic no.of rows ) into different columns

    Good call it would be great to know which is faster

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: convert different rows ( dynamic no.of rows ) into different columns

    Hi there here is a solution using the PIVOT function

    -- no col1 col2 col3 col4 col5

    -- 1 aaa bbb ccc null null

    -- 2 vvv nnn null null null

    /*

    CREATE TABLE #tmpTest...

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: Common Table Expression

    Hi there,

    TRy creating a function that uses a Tally table.

    Here is my solution:

    CREATE FUNCTION [dbo].[Split]

    (

    @String NVARCHAR(100) ,

    @Delimiter CHAR(1)

    )

    RETURNS @Results TABLE

    (ID INT IDENTITY(1,1),

    String VARCHAR(100))

    AS

    BEGIN

    INSERT INTO @Results

    SELECT SUBSTRING(@String+@Delimiter, n,

    CHARINDEX(@Delimiter, @String+@Delimiter,...

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: Update statement

    TRy this.

    UPDATE e

    SET e.passportcode = p.passportcode

    FROM Employee e

    INNER JOIN Passport p ON p.EmployeeId = e.EmployeeId

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: updatestatement

    Hi there,

    Which version of SQL are you using as I see you have posted this on 2000 and 2005 forums

    Please could you remove one of them?

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: Update statement

    Is this homework?

    If you let us know what you have tried so far then we can guide you in the correct direction 🙂

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: CASE vs Pivot

    Thanks all for the feedback 🙂

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • RE: How to get total time for each employee

    My Answer is in Months

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life

Viewing 15 posts - 706 through 720 (of 1,082 total)