Forum Replies Created

Viewing 15 posts - 6,841 through 6,855 (of 8,731 total)

  • RE: Sum values on periods

    Here's the final solution with the gaps problem solved (Hoping you won't have dates that go over 25 years in the future).

    WITH E1(N) AS(

    SELECT N FROM( VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))E(N) --10 rows

    ),

    E2(N) AS(

    SELECT...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Query Statement Help with data Type as Integers

    With the Information_Schema views, this kind of queries become easier.

    DECLARE @sql VARCHAR(MAX)

    SELECT @sql = (SELECT 'SELECT ' +

    STUFF( (SELECT ',' + COLUMN_NAME

    FROM INFORMATION_SCHEMA.COLUMNS x

    WHERE DATA_TYPE = 'int'

    AND x.TABLE_NAME =...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: UPDATE SQL Query Help !

    It would be as simple as this, as explained in the article:

    SELECT t.AID,

    Emails = STUFF((SELECT '; ' + t1.EmailID

    FROM #TEST1 t1

    WHERE t1.AID = t.AID

    FOR XML PATH('')), 1, 2, '')

    FROM...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: How to use PATINDEX with a variable containing '[' and ']'

    This will return the correct results but only if you change your filename data type to varchar:

    SELECT CHARINDEX(@filename,@FILEPATH), PATINDEX('%' + REPLACE( @filename, '[', '[[]') + '%',@FILEPATH)

    This should show you the...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Sum values on periods

    This might help others to complete the requirement (and maybe improve it). It's missing the gaps problem (shown on store 4).

    If the gaps aren't a problem, then this should do...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: How to use PATINDEX with a variable containing '[' and ']'

    Is the bold part an error on your post or on your query?

    SELECT PATINDEX('%[[]' + @filename + '][]%',@FILEPATH)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Update from Select Statment

    If you format your code, it should be clear.

    UPDATE AxysPriceFile

    SET CurrentPX = Moxy.Price

    WHERE Type = Moxy.SecType

    AND Ticker = Moxy.Symbol

    IN /*What column should be...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: DateAdd Convertion Problem

    To complete previous post.

    If you change your scalar function into an inline table-valued function, your queries should perform a lot better. Check this article for more information:

    This is an...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: DateAdd Convertion Problem

    The problem is that @d is a varchar. To use DATEADD, SQL Server converts @d to datetime and then back to varchar to assign it to @d. The second conversion...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: UPDATE SQL Query Help !

    sqldba20 (2/20/2014)


    Nevermind...I was able to figure out using the link posted by Luis. Came with this SQL and it works.

    How on earth did you figure that out from the link...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: How to divide by a subquery

    It should be more efficient as it only reads the table once instead of twice.

    You could test it and check the differences on larger tables.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Sum values on periods

    How do you define that it goes from 10 to 15 and then back to 5?

    It looks like a running total problem. Before 2012, those problems have several solutions, the...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: Need help with pivot?

    As you're quite new with SQL and this site, I'm creating sample data in a way that we can just copy and execute it. You're expected to do this and...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: UPDATE SQL Query Help !

    sqldba20 (2/20/2014)


    It is only for display purpose in reporting because the user doesn't want to see 4 rows for each record if there are 4 email ids for that AID.

    So,...

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • RE: How to divide by a subquery

    You don't need to scan the table twice 😉

    SELECT Id, layer,

    SUM(CASE WHEN test > 1 THEN test * duration END) /

    SUM(duration * 1.0)

    FROM #test

    GROUP BY ID,

    layer

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 15 posts - 6,841 through 6,855 (of 8,731 total)