Forum Replies Created

Viewing 15 posts - 706 through 720 (of 897 total)

  • RE: using CASE in WHERE clause

    Anamika (7/19/2010)


    Thanks to Eugene and mthurber nice and easy way of achieving it.

    by the way, Mr. Paul, i still don't understand the logic behind it.

    SELECT * FROM Tbl1

    I think Paul...

  • RE: SUBSTRING coding problem

    Paul White NZ (7/17/2010)


    A small modification, to allow for input strings that include one or more trailing spaces, and which will also work with a Unicode input string:

    DECLARE @strVariable VARCHAR(100)...

  • RE: joins to the same table

    All you have to do is replace the m in the last line with m1 in your query

    select id1

    ,orderby

    ,m.Name orderbyname

    ,m1.Name receivedbyname

    from @staff m

    inner join @order t

    on m.id =...

  • RE: SUBSTRING coding problem

    Jeff Moden (7/16/2010)


    Kingston Dhasian (7/16/2010)


    Try this

    DECLARE @strVariable VARCHAR(100)

    SET @strVariable = 'J:\SQL 2008 Database Backups\High School Baseball\HighSchoolBaseball_Full.bak'

    SELECTSUBSTRING( @strVariable, 1, LEN( @strVariable ) - CHARINDEX( '\', REVERSE( @strVariable ) ) )

    Here i...

  • RE: SUBSTRING coding problem

    Try this

    DECLARE @strVariable VARCHAR(100)

    SET @strVariable = 'J:\SQL 2008 Database Backups\High School Baseball\HighSchoolBaseball_Full.bak'

    SELECTSUBSTRING( @strVariable, 1, LEN( @strVariable ) - CHARINDEX( '\', REVERSE( @strVariable ) ) )

    Here i have used the REVERSE...

  • RE: how to use execution plan

    This is quite a big topic and people have written whole books on it. I can give you a link of books which have the anwers to your questions in...

  • RE: Return distinct results where multiple rows have different values

    This is what i could come up with.

    DECLARE@tbl_OrderItems TABLE

    (

    OrderID INT,

    Product VARCHAR(100)

    )

    INSERT@tbl_OrderItems

    SELECT10001, 'Bananas' UNION ALL

    SELECT10002, 'Apples' UNION ALL

    SELECT10002, 'Pears' UNION ALL

    SELECT10002, 'Oranges' UNION ALL

    SELECT10003, 'Bananas' UNION ALL

    SELECT10004, 'Apples' UNION ALL

    SELECT10004, 'Pears'

    SELECTDISTINCT...

  • RE: Transform Rows to Columns

    IF OBJECT_ID( 'tempdb..#Employees' ) IS NOT NULL

    DROP TABLE #Employees

    DECLARE@strColumns VARCHAR(1000)

    DECLARE @strQuery VARCHAR(2000)

    CREATE TABLE #Employees

    (

    EMP_IDINT,

    Contact_typeNVARCHAR(50),

    Contact_NumberNVARCHAR(300)

    )

    INSERT INTO #Employees

    SELECT 1 ,'Home' ,'92 - 51 - 225478'

    UNION ALL SELECT 1, 'Cell', '92...

  • RE: Solution Required for Mentioned Result.

    You can also get your desired result by replacing the LEFT JOIN IN Wayne's Code with a FULL OUTER JOIN

    SELECTISNULL( t2.SID, t1.SID ) SID, ISNULL( t2.PID, t1.PID ) PID,

    ISNULL( t2.Date,...

  • RE: order by twice

    Chris Morris-439714 (6/29/2010)


    eng.khiat (6/29/2010)


    SELECT * FROM

    (

    SELECT top 10 * FROM tableX ORDER BY ID DESC

    ) AS A

    ORDER BY A.ID ASC

    It gives error and when...

  • RE: order by twice

    Try the following

    ; WITH cte_tableX AS

    (

    SELECTROW_NUMBER() OVER ( ORDER BY ID DESC ) RowNum, *

    FROMtableX

    )

    SELECT*

    FROMcte_tableX

    WHERERowNum <= 10

    ORDER BY RowNum DESC

    Didnt test it though. But should work

  • RE: Query Help

    Gianluca Sartori (6/25/2010)


    virender.singh (6/25/2010)


    derived/nested query is ok. but we will have a performance issue with this.

    What kind of performance problem? The way of accessing the table suggested by Kingston isn't...

  • RE: Query Help

    Glad we could help you out:-)

  • RE: Query Help

    NewBeeSQL (6/25/2010)


    I Missed two more joins (part of PK) in my earlier post. am updating the Kingstons final query to get the correct result.

    ;with cte1 as(select ROW_NUMBER() OVER(ORDER BY...

  • RE: Query Help

    Change the block as given below, I have just used a COALESCE() function to get the desired result

    ;with cte1 as(select ROW_NUMBER() OVER(ORDER BY Index_code) AS 'rn',index_code,code1,code2,startdate,enddate

    from #Ixtable)

    select c1.index_code,c1.code1,c1.code2,c1.startdate, -- c2.startdate-1...

Viewing 15 posts - 706 through 720 (of 897 total)