Forum Replies Created

Viewing 15 posts - 271 through 285 (of 898 total)

  • RE: How to write a select query that shows upcoming birthdays

    One way to do this

    DECLARE@person TABLE

    (

    person_name VARCHAR(50),

    date_of_birth CHAR(8)

    )

    DECLARE@start_date CHAR(4)

    DECLARE @end_date CHAR(4)

    INSERT@person

    SELECT 'A', '19800101' UNION ALL

    SELECT 'B', '19700605' UNION ALL

    SELECT 'C', '19650525' UNION ALL

    SELECT 'D', '19901020'

    SET@start_date = RIGHT(CONVERT(CHAR(8),CURRENT_TIMESTAMP,112),4)

    SET@end_date = RIGHT(CONVERT(CHAR(8),DATEADD(DAY,29,CURRENT_TIMESTAMP),112),4)

    SELECT*

    FROM@person

    WHERERIGHT(date_of_birth,4) BETWEEN...

  • RE: How to write a select query that shows upcoming birthdays

    eklavu (5/21/2013)


    HOPE THIS HELP

    DECLARE @TABLE_NAME TABLE(

    NAME VARCHAR(30),

    BDAY CHAR(8))

    INSERT INTO @TABLE_NAME(NAME,BDAY)

    VALUES('A','20130522')

    INSERT INTO @TABLE_NAME(NAME,BDAY)

    VALUES('B','20130523')

    INSERT INTO @TABLE_NAME(NAME,BDAY)

    VALUES('C','20130524')

    INSERT INTO @TABLE_NAME(NAME,BDAY)

    VALUES('D','20130525')

    INSERT INTO @TABLE_NAME(NAME,BDAY)

    VALUES('E','20130521')

    INSERT INTO @TABLE_NAME(NAME,BDAY)

    VALUES('F','20130620')

    SELECTNAME,

    DATEDIFF(DAY,GETDATE(), CAST(BDAY AS DATETIME)) [BDAY WITHIN 30 DAYS]

    FROM@TABLE_NAME

    WHEREDATEDIFF(DAY,GETDATE(), CAST(BDAY AS...

  • RE: select records from a table where the records belong to fist clienname when ordered in ascending order of clientname

    In that case you can use ROW_NUMBER() to get the desired result

    With MyCTE (clientName,col2,col3,col4)

    AS

    (

    SELECT 'A123','val1','val2','val3' UNION ALL

    SELECT 'A123','val4','val5','val6' UNION ALL

    SELECT 'B234','val7','val8','val9' UNION ALL

    SELECT 'C789','val1','val5','val6' UNION ALL

    ...

  • RE: Display -0

    You will need CASE statement and some hard-coding to achieve this result

    SELECTCASE WHEN SUM(trans_amt) BETWEEN -0.99 AND 0 THEN '-0.00' ELSE CAST( SUM(trans_amt) AS VARCHAR(30)) END

    FROMacc_bal_may

  • RE: Display -0

    Getting -0 as result after performing some numeric operation is not possible

    We will have to do some string concatenation to achieve this result

    Can you give a bit more details as...

  • RE: Parent child relationship in separate tables

    kunal.desai 7690 (5/19/2013)


    Hey,

    Many many thanks,

    This worked like a gem. I met my objective with this solution.

    Regards,

    K

    Glad I could help you out 🙂

  • RE: sqlCursor

    I don't think you require a CURSOR to do this kind of stuff

    Please go through the article in my signature and give us the DDL of the tables involved, some...

  • RE: Parent child relationship in separate tables

    We may need non set-based methods to achieve the result you need

    I have a set-based solution which gives you different results in terms of numbers, but the objective is the...

  • RE: Check each cell in one table and update another table

    adonetok (5/16/2013)


    I do not know how to post real table but I did the same case using .net in application (create a dataset and then looping in dataset).

    Now, I...

  • RE: Check each cell in one table and update another table

    adonetok (5/16/2013)


    In fact, in real table there are about 20 colums and 200 ID need to check cell by cell.

    I do not think that without loop can do it.

    Can someone...

  • RE: Check each cell in one table and update another table

    Your requirements are not very clear

    Can you provide the DDL of the tables involved, data and the expected results in a ready to use format

    Please check the link in my...

  • RE: Problem in Dynamic sql

    Please post the exact error message that you are getting.

  • RE: get max

    One way of doing this..

    SELECTa.name, b.[DATE], b.[ORDER]

    FROMdbo.Table_A a

    LEFT OUTER JOIN(

    SELECTROW_NUMBER() OVER( PARTITION BY b.ID ORDER BY b.[DATE] DESC ) AS RN, *

    FROMdbo.Table_B AS b

    ) AS b ON a.id = b.ID...

  • RE: Best way to do same.

    One more way to do this..

    SELECT*

    FROMmain AS m

    WHERE NOT EXISTS( SELECT * FROM doc AS d WHERE m.fileno = d.fileno AND d.code = 'I' )

    We can't say that one method...

  • RE: Adding Rows to an existing table sql 2005

    kgeeel240 (4/29/2013)


    Thank you it worked!!!!:w00t:

    Glad it helped:-)

Viewing 15 posts - 271 through 285 (of 898 total)