Forum Replies Created

Viewing 15 posts - 5,146 through 5,160 (of 8,731 total)

  • RE: Flip data in SQL

    helal.mobasher 13209 (3/3/2015)


    Thanks Luic for dynamic SQL. Very elaborate and I need to test it. However, on your note "Are you seriously taking the advice and code from someone 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: Find patients with age 6 months to 5 years

    Do you mean at the date of the appointment?

    SELECT *

    FROM TEST

    WHERE DOB BETWEEN DATEADD(YYYY, -5, ApptDt2) AND DATEADD(MM, -6, ApptDt2)

    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: Create a dynamic date

    ron.grace 36037 (3/3/2015)


    A few attempts to get the right syntax, but got there eventually, many thanks

    @Dest1 + (DT_STR, 4 , 1252)DATEPART( "year" , GETDATE() ) + "" + RIGHT( "00"...

    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: Help calculating the age from the date of birth in table

    It's been a while since I'd use or suggest a scalar function as a solution to a problem.

    Instead, this should do it.

    SELECT dob,

    CASE WHEN DATEADD(YYYY, DATEDIFF(YYYY,...

    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: Help calculating the age from the date of birth in table

    Do you have errors in your calculations (getting incorrect age) or errors thrown by SQL Server that might come from incorrect data?

    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 question, possible subquery?

    SQL_NuB (3/2/2015)


    ScottPletcher (3/2/2015)


    You really should leave the columns separate in the other table as well, but here's how to do the join with the combined column:

    SELECT ...

    FROM table1 t1

    INNER JOIN...

    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 to create file with name and current time stamp.

    Your first problem which generates an error is that you're missing quotes in your last 2 steps. This will throw an error when your path has spaces in it.

    ALTER procedure...

    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: Maximum number of databases per instance

    I wonder if the answer is incorrect because the maximum number of databases in an instance is 32,767.

    But you can create as many databases as you wish as long as...

    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: Help to complete "order by" statement

    Of course, if you're returning just 4 rows it won't make a difference. 🙂

    As with most things in SQL, it depends.

    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 to create file with name and current time stamp.

    The problem is that we don't know what's inside of p_CreateExcel. The code creates what I suppose is a valid path with a file that includes the date. I'm not...

    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: Help to complete "order by" statement

    This is going to be slow.

    You might gain speed with an additional order column. It could be a persisted computed column.

    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: Case statement within a where clause - based on 2 variables

    I would simplify it.

    SELECT Customer, [Type], DueDate1, DueDate2

    FROM dbo.myTable mt

    WHERE mt.[Type] = @Type

    AND (mt.DueDate1 BETWEEN @DueDate1 AND @DueDate2 OR @Condition1 = 0)

    AND (mt.DueDate2 BETWEEN @DueDate1 AND @DueDate2 OR @Condition2...

    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: Flip data in SQL

    This is how I would do it.

    For references:

    Creating the dynamic code[/url]

    Unpivoting the data[/url]

    DECLARE @sql nvarchar(4000);

    SELECT @sql = 'SELECT t1.ID, t1.Name, ca.YrMnth, ca.Enrollment

    FROM #Table1...

    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: WITH (NOLOCK) Question

    Katerine459 (2/27/2015)


    ... what is that?

    This generates a Tally table on the fly with zero reads.

    Could you please take me through what that does? Your comment, "Enough for 12 years"...

    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: WITH (NOLOCK) Question

    This is an option. It's not perfect but should be better that your current process. Someone else could improve the code. It would be nice to know what are you...

    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 - 5,146 through 5,160 (of 8,731 total)