Forum Replies Created

Viewing 15 posts - 7,246 through 7,260 (of 8,731 total)

  • RE: Convert SQL Server Date to DD/MM/YY

    Oh my, so much code! My laziness wants to write less.

    declare @SSDate datetime = '20140109'

    declare @CharSSDate char(10)

    SELECT CONVERT( char(10), @SSDate, 103), --4-digit year

    STUFF( CONVERT( char(10), @SSDate, 103), 7, 2,...

  • RE: Unravel Some Complex IF Logic

    Thomas Abraham (1/9/2014)


    Let's try to simplify:

    By default, "Options 1, 2 and 4 are equivalent and identical to the original code" is the remaining answer that has not already been proven...

  • RE: Complex Query. Please help

    eli.misael (1/8/2014)


    other solution is using the CTE and PIVOT like the follow script, in the sample I define the tables, but you can use your defined tables and only use...

  • RE: help with insert query

    dwain.c (1/8/2014)


    Luis - This is nice! Also out of the box.

    select [object_id]

    INTO #TableB

    from sys.all_objects

    WHERE 1=2

    That was very common at my first job to avoid writing the definition of...

  • RE: SLICING DATA IN A TABLE

    I'm sure that this is a running total problem that I would love to try with SQL 2012, but I don't have it at work.

    There's another option that works great...

  • RE: help with insert query

    Here's an example:

    select *

    INTO #TableB

    from sys.all_objects

    WHERE 1=2

    select top 1000 *

    INTO #TableA

    from sys.all_objects

    WHILE @@ROWCOUNT > 0

    BEGIN

    INSERT INTO #TableB

    SELECT TOP 100 *

    FROM #TableA a

    WHERE NOT EXISTS(SELECT * FROM #TableB b...

  • RE: help with insert query

    Why would you do that? How can you identify which rows you have inserted and which rows you haven't?

  • RE: FOR XML function converting "&" to "&"

    Change

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

    To

    FOR XML PATH(''), TYPE).value('.','varchar(max)'),1,1,'')

  • RE: Stored Procedure drop table

    You could set up a job in the SQL Server Agent.

  • RE: Stored Procedure drop table

    You actually don't need the following line

    DECLARE @cmd VARCHAR(MAX)

    As said, you would be better deleting the information from the table. You could use TRUNCATE TABLE for performance, but it has...

  • RE: Conversion failed when converting the varchar value '1*2*3' to data type int.

    You can't assign the result of a formula directly to a variable. You would need to use dynamic code.

    Here's an example:

    DECLARE @MYFOR AS NVARCHAR(100), @Result int

    SET @MYFOR ='V6*2*3'

    SELECT @MYFOR =...

  • RE: CAST in AND statement

    You have a problem with your nesting. You're opening your cast before the case and closing it in the middle of the case. It has to be either all out...

  • RE: Flat File connection not fixed width but the row length is !!

    What about importing last column as a string and using a derived column to validate and convert value into int?

  • RE: DBAs Need to Learn to Develop

    Jeff Moden (1/7/2014)


    eccentricDBA (1/7/2014)


    I agree that a DBA should learn how to develop. At the very least they should learn how to use a scripting language (dos batch, bash,...

  • RE: Convert String to DateTime

    You could truncate your values to 23 positions or you could convert them to datetime2

    CREATE TABLE #Test(

    chardatevarchar( 50))

    INSERT #Test VALUES(

    '2013-01-09 11:32:00'),(

    '2013-02-14 20:22:37.033000000'),(

    '2013-05-05 23:11:15.013000000'),(

    '2013-06-14 15:20:36.030000000'),(

    '2013-01-09 11:29:00')

    SELECT *, CAST(LEFT( chardate, 23)...

Viewing 15 posts - 7,246 through 7,260 (of 8,731 total)