Forum Replies Created

Viewing 15 posts - 7,336 through 7,350 (of 8,731 total)

  • RE: can't trap error

    If you're using 2012 (or 2005+) you should use TRY...CATCH

    SET NOCOUNT ON;

    DECLARE @sql NVARCHAR(101)='SELECT 1/0'

    DECLARE @r Table (R INT)

    DECLARE @T Table (Z INT)

    BEGIN TRY

    BEGIN TRANSACTION

    INSERT INTO @r

    EXECUTE...

    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: split column into multiple records based on substring fixed lenght

    You need to add an additional ROW_NUMBER() instead of the previously generated n.

    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: Pivot Rows to Columns with UnEven amounts of Rows based on Monthly Dates

    I'm glad I could help. You made it easy. Thank you for taking the time of posting with all the details.

    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: Efficient Methodology

    Maybe I'm missing something but it seems that you're not using any column from table employee. You could remove it. If you need the information, I would join it out...

    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: Pivot Rows to Columns with UnEven amounts of Rows based on Monthly Dates

    I hope this will help you. You just need to complete the rest of the months with Copy-Paste-Replace.

    WITH CTE AS(

    SELECT TOP 12 DATEADD( mm, (ROW_NUMBER() OVER(ORDER BY(SELECT NULL)) -1) *...

    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: Efficient Methodology

    Both queries are not equivalent. The first will return 10 rows and the second one will return 10 rows per EmpID.

    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: Extract the data based on the present quarter and last quarter

    There's not enough information to help you.

    Please post DDL, sample data and expected results as explained on the article linked in my signature.

    We're willing to help but we can't see...

    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: Pivot Rows to Columns with UnEven amounts of Rows based on Monthly Dates

    The DDL and sample data were helpful. You could use the IFCode tags to avoid having a very large post and keep formatting but that's just style. 🙂

    I got lost...

    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: Pivot Rows to Columns with UnEven amounts of Rows based on Monthly Dates

    I'm not sure if this will help you but it sounds as if you need a calendar table (I used a CTE to get the needed months). I hope this...

    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 on improving a where clause, thanks.

    There are several ways of doing that.

    and ( @RoleID = 5

    OR g.ID in

    (Select ID From Groups where GroupName = 'SVP - LATAM'

    Union ALL

    Select ID From Groups where Sub =...

    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: Table row count grouped by date

    Maybe something like this might help.

    Note that there's commented code that you might need to use to get the correct results.

    CREATE TABLE ##Counts(

    Table_Namenvarchar(128),

    Whendate,

    RecCount int --bigint

    )

    DECLARE @sql nvarchar(MAX)= ''

    SELECT @sql =...

    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: Remove DATE ONLY from datetime column

    You just have to play with format codes 🙂

    SELECT TOP 100

    SUBSTRING( CONVERT(varchar,create_date,109), 13, 14) As CharTime

    FROM sys.objects

    REFERENCE: http://msdn.microsoft.com/en-us/library/ms187928.aspx

    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: split column into multiple records based on substring fixed lenght

    It's easy to combine both techniques. Here's an example returning rows with 4 characters or less.

    WITH E1(n) AS(

    SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL 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: retrive

    Good luck with your homework.

    To get some help, feel free to read the article linked on my signature.

    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: Why we used Aggregate function in pivot and cross tab queries ?

    2 great articles by Jeff Moden on the subject:

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

    http://www.sqlservercentral.com/articles/Crosstab/65048/

    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 - 7,336 through 7,350 (of 8,731 total)