Forum Replies Created

Viewing 15 posts - 766 through 780 (of 897 total)

  • RE: Trigger For Delete - Multiple Row Value

    If you want to do an UPDATE for all the deleted rows, the query provided by me will work fine. You don't need to put any Where Clause.

    If you want...

  • RE: Trigger For Delete - Multiple Row Value

    You can use a simple join to do this

    UPDATESW

    SETcount = count - 1

    FROMsomewhere SW

    INNER JOIN deleted D ON SW.idsomewhere = D.id

  • RE: Generating delete statement from tablename stored in another table

    gaurav-404321 (4/17/2010)


    This is not working. Stored prcoedure is returning the query as :

    DELETE FROM sectionnumeric

    FROM dbo.CreateSectionTableFromString(placementcandidatelanguageproficiency,placementcandidatetrainingsinternshipsprojects,placementcandidatequalificationdetails)

    This query is giving lot of errors. I think some syntax mistake...

  • RE: selecting column name dynamically

    You can use Dynamic SQL for the same

    DECLARE@strSQLVARCHAR(500)

    DECLARE@toUpdateVARCHAR(100)

    DECLARE@selecteditemVARCHAR(100)

    SELECT@toUpdate = 'var2_N',

    @selecteditem = 'var1_N'

    SELECT@strSQL = ' UPDATE dbo.tbl_data '

    + ' SET var2 = ' + @toUpdate

    + ' WHERE var1...

  • RE: Generating delete statement from tablename stored in another table

    Is your expected output

    DELETE FROM placementcandidatelanguageproficiency

    DELETE FROM placementcandidatetrainingsinternshipsprojects

    If it is so, then you can create the script using Dynamic SQL

    DECLARE@strSQL VARCHAR(MAX)

    SELECT@strSQL = COALESCE( @strSQL + CHAR(10), '' )

    + ' DELETE...

  • RE: Select first grandchild row of first child

    You can also use a CROSS APPLY for the same

    selectT.*

    fromTrip Tr

    cross apply (

    selecttop 1 Trip.id, TrackPoint.lat, TrackPoint.lon

    from TrackPoint

    join Track on Track.id = TrackPoint.trackID

    ...

  • RE: Select first grandchild row of first child

    You can use ROW_NUMBER() for the same

    ; WITH cte_Track_Details AS

    (

    SELECTROW_NUMBER() OVER( PARTITION BY Trip.id ORDER BY Trip.id, TrackPoint.lat, TrackPoint.lon ) RowNum,

    Trip.id, TrackPoint.lat, TrackPoint.lon

    FROMTrackPoint

    INNER JOIN Track ON Track.id =...

  • RE: how to get only latest date and other columns from table

    You can use the ROW_NUMBER() function

    ; WITH cte_Table AS

    (

    SELECTROW_NUMBER() OVER ( PARTITION BY id, name ORDER BY date DESC ) Row_Num, *

    FROMTable

    )

    SELECT*

    FROMcte_Table

    WHERERow_Num = 1

  • RE: Left Join, Count, WHERE clause, Headache

    COldCoffee (4/13/2010)


    Kingston's code will also work but for a small change..you will have to Group By some columns... guess kingston is not near his SSMS and have not compiled...

  • RE: Left Join, Count, WHERE clause, Headache

    Does this help..

    SELECTO.OwnerID, O.Owner_Name, COUNT( P.Pet_id ) [Count]

    FROMOWNER O

    LEFT OUTER JOINPET P

    ON O.Owner_id = P.Owner_id

    AND P.Pet_Age > 4

  • RE: How to send mail using Sql Server

    Look for sp_send_dbmail in Books Online or Google.

  • RE: Substring Error

    You will have to do this for the 2nd and 3rd parameter. But in your case the 2nd parameter cannot be negative. But you can still check to be sure..

  • RE: Merging of rows

    ; WITH cte_Schedule_Audit AS

    (

    SELECTROW_NUMBER() OVER( PARTITION BY ID, Action ORDER BY ID, ModifiedOn DESC ) RowNum, *

    FROM#Schedule_Audit

    )

    SELECTI.ID, I.M_ID, I.T_Name, I.T_Desc, I.Sch_Time, I.CreatedBy, I.CreatedOn, U.ModifiedBy, U.ModifiedOn,

    D.DeletedOn, D.DeletedBy

    FROMcte_Schedule_Audit I

    LEFT JOIN cte_Schedule_Audit U...

  • RE: Substring Error

    See if this query returns any negative values

    SELECT

    CHARINDEX('/',LineRead,CHARINDEX('/',LineRead)+ 1)-1 - CHARINDEX('/',LineRead)

    ,CHARINDEX('/',LineRead,CHARINDEX('/',LineRead,CHARINDEX('/',LineRead)+ 1)+1)-1

    - CHARINDEX('/',LineRead,CHARINDEX('/',LineRead)+ 1)

    ,CHARINDEX('/',LineRead,CHARINDEX('/',LineRead,CHARINDEX('/',LineRead,CHARINDEX('/',LineRead)+ 1)+1)+1)- 1 -

    ...

  • RE: Removing identity property

    Yes, tried it just now. It doesn't work. I thought the alias name was the problem, hence didn't test. Even i would have done the same in such a case....

Viewing 15 posts - 766 through 780 (of 897 total)