Forum Replies Created

Viewing 15 posts - 316 through 330 (of 337 total)

  • RE: Pivot Query Question

    joshtheflame (11/14/2010)


    I dont have MONTH COLUMN in my table 🙂 as I am populating days of the month dynamically all i have is TASK_ID, TASK_DATE, TASK_COUNT ...thats it..now how to...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: resume after error for primary key violation

    @bitbucket

    First of all did you test the query I posted earlier?

    The first query does exactly what the OP wants.It continues to execute rest of the script even though there is...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Pivot Query Question

    --Put it all together into a pivot query.

    set @sql = 'SELECT Task_Name, ' + @columnnames + ' , Total FROM (';

    set @sql = @sql + 'SELECT M.Task_Name, D.Task_Date, D.Task_Count, Sum(D.Task_Count)...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Converts in a case expression

    OR

    Try this

    WHEN COUNT(customer_id) = convert(varchar(2),0) THEN 'No customers' ELSE COUNT(customer_id) END

    PS - I haven't tested it

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: resume after error for primary key violation

    When SET XACT_ABORT is OFF,in some cases only the Transact-SQL statement that raised the error is rolled back and the transaction continues processing. Depending upon the severity of the error,...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Pivot Query Question

    You can change your @sql part to something like below.I cannot test it since you didn't post your table structure and sample data.

    Notice the new column name "TaskTotal"

    --Put it all...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: TSQL Best Functionalities needed

    I wouldn't waste my time posting the answers for OP.He is applying for a job he is not eligible for as simple as that.

    He should get the required experience or...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: resume after error for primary key violation

    set xact_abort off

    go

    CREATE TABLE #T(Cod VARCHAR(30)primary key)

    INSERT INTO #T SELECT 'jkl'

    INSERT INTO #T SELECT 'lmn' --Duplicate entry in input stream

    INSERT INTO #T SELECT 'abc'

    INSERT INTO #T SELECT 'lmn'...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Using the salary table on the left, write a SQL Server T-SQL query to find the Top 2 salaries for each employee. The result of the query is on the right.

    Also my solution will work for SQL 2005 and later.

    I am assuming you are using a version greater than SQL 2000 since you have posted your question in SQL 2005...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Using the salary table on the left, write a SQL Server T-SQL query to find the Top 2 salaries for each employee. The result of the query is on the right.

    rko.37gags (11/9/2010)


    Come on Dude....Just tell me.....what is "T" in that query

    This is something called as a "derived table" which encapsulates the result of a SELECT statement in the FROM...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Using the salary table on the left, write a SQL Server T-SQL query to find the Top 2 salaries for each employee. The result of the query is on the right.

    rko.37gags (11/9/2010)


    Thanks for ur reply....Some doubts..

    select * from

    (

    select *,row_number()over(partition by employeeid order by salary desc)rid from salary

    )T where rid<=2

    what is rid and T

    You really wanna know?

    I thought you would rather...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Using the salary table on the left, write a SQL Server T-SQL query to find the Top 2 salaries for each employee. The result of the query is on the right.

    Craig Farrell (11/9/2010)


    Sachin.Nandanwar (11/9/2010)


    rko.37gags (11/9/2010)


    i attached the excel file

    Now that's better.

    Below is your query.

    select * from

    (

    select *,row_number()over(partition by employeeid order by salary desc)rid from salary

    ...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Using the salary table on the left, write a SQL Server T-SQL query to find the Top 2 salaries for each employee. The result of the query is on the right.

    rko.37gags (11/9/2010)


    i attached the excel file

    Now that's better.

    Below is your query.

    select * from

    (

    select *,row_number()over(partition by employeeid order by salary desc)rid from salary

    )T where rid<=2

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: Using the salary table on the left, write a SQL Server T-SQL query to find the Top 2 salaries for each employee. The result of the query is on the right.

    rko.37gags (11/9/2010)


    Plz post me the query.....i didnt understand ur "Blah Blah"

    OK.So here is the answer

    select * from table

    A "Blah Blah" answer for a "Blah Blah" question posted by "Blah...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • RE: date calculations

    bitbucket-25253 (11/9/2010)


    Is this what you are seeking:

    SELECT DATEADD(mm,-3,DATEADD(day, 1, GETDATE()))As '3 months ago',GETDATE() AS 'Today',

    DATEADD(day, 1, GETDATE()) AS 'Today plus 1 day'

    Results:

    3 months ago ...

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

Viewing 15 posts - 316 through 330 (of 337 total)