Forum Replies Created

Viewing 15 posts - 2,431 through 2,445 (of 2,458 total)

  • RE: Need help in T-sql to get the Last Year's first 4 week sales data

    First, by "count of" sales I assume you mean SUM of sales. Otherwise we'd be looking at a result set a little more like:

    WeekEndDate SalesTotal

    2011-01-07 1

    2011-01-14 1

    2011-01-21 1

    2011-01-28 1

    Lets try...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Get running total in the following query

    Sean Lange (7/18/2012)


    See if this article helps. http://www.sqlservercentral.com/articles/T-SQL/68467/%5B/url%5D

    Jeff's article is certainly a must-read on this topic.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Get running total in the following query

    a2zwd (7/18/2012)


    Hi

    I have a table which holds the running total.

    DECLARE @CumCredit TABLE(RowId INT, CustomerId INT, TransId INT, Pts INT, RunningTotal INT)

    INSERT INTO @CumCredit VALUES(1,123,121,10,10), (2,123,131,20,30), (3,123,141,15,45)

    New resultset which needs to...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: how to login into ssms

    harri.reddy (7/17/2012)


    hi

    i need to add my user name into ssms,how to login first in order to add another user.

    like sa or what password?

    First, a little more detail would help here....

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: xp_cmdshell

    SQLSACT (7/17/2012)


    Hi All

    How would I setup a script to copy files from a shared location on one server, to a shared location on another server?

    The extension of the files would...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: restricting values a variable can be assigned

    dndaughtery (7/17/2012)


    Is there a way to do it in the declaration?

    I was told someone interviewing me would ask this. In my 7 years of DB Development Ive never had a...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: How do I get the all columns of a row for the row with the highest value of a column

    -- Sample code

    CREATE TABLE #T(ID INT, Unit INT)

    INSERT INTO #t

    SELECT 1,33 UNION ALL

    SELECT 2,33 UNION ALL

    SELECT 3,25 UNION ALL

    SELECT 4,55 UNION ALL

    SELECT 5,55

    -- Query

    SELECT MAX(ID) ID, MAX(Unit) Unit

    FROM #t

    GROUP BY...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Please help me with this query

    Sean Lange (7/12/2012)


    The whole series of subselects sure makes that far more complicated than it needs to be.

    Not sure if what you posted produces what the OP wants but this...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Please help me with this query

    I think this is what you are looking for.

    -- Sample data

    DECLARE @salesStore TABLE([CustomerID] VARCHAR(20));

    DECLARE @MyTable TABLE(val varchar(20));

    INSERT INTO @salesStore VALUES ('xxx'),('yyy'),('zzz');

    -- Insert statement

    INSERT INTO @MyTable

    SELECT * FROM

    (

    VALUES ('Store'),('CustomerID'),('int'),('10'),('Sales'),('CustomerID'),('PK_Store_CustomerID')

    )...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Converting yyyy/mm/dd hh:mm:ss

    CELKO (7/11/2012)


    There is only one display format in ANSI SQL; the ISO-8601 version with dashes "yyyy-mm-dd HH:MM:SS.sssssss". Please notice I said display format.

    SQL is an abstract model of data. We...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Renamed AD users' accounts, now some SQL Servers can't get info

    schleep (7/11/2012)


    We changed some users AD accounts to a new name (samaccountname, displayname, logon, etc..)

    On one SQL server (2 instances), we get the following error on setuser.

    Could not obtain information...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Converting yyyy/mm/dd hh:mm:ss

    sqluser_8119 (7/11/2012)


    How do you make this:

    yyyy/mm/dd hh:mm:ss

    Look like this:

    mm/dd/yyyy hh:mm --hh:mm needs to be in military time

    DECLARE @date datetime = '2012/06/20'

    SELECT CONVERT(CHAR(10), CONVERT(datetime, @date,103),101)

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: Loop within a Loop

    SGT_squeequal (7/11/2012)


    Racking my brains on this one, does anyone know if it is possible to do a while loop with in a while loop?

    what i want to do is...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: SQL Variable IF Clause

    SQLSeTTeR (7/11/2012)


    Alan - Thank you very much. This did the trick.

    No problem.:cool:

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • RE: SQL Variable IF Clause

    Sony Francis @EY (7/11/2012)


    We can simplify the above query to

    select @v-2 =case when t1.col2 like '%*%' then t2.col2 else t1.col2 end

    from @table1 t1,...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 15 posts - 2,431 through 2,445 (of 2,458 total)