simple delete statement

  • What would be delete statement

    for this

    I want to delete KSCHLKO FROM 'KSHLKO100' WHICH IS LOCATED IN COLUMN

    Thank you in advance

  • DELETE t

    FROM YourTable t

    WHERE Column = 'SomeValue'

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • DELETE ABCDEF FROM dbo.XYZ

    WHERE Column = 'ABCDEF100'

  • Thank you for your reply. Per your advice,

    I created

    DELETE ABCDEF FROM dbo.XYZ

    WHERE Column = 'ABCDEF100'

    want to delete ABCDEF AND LEAVE 100 IN THAT COLUMN

    Plz help me create statement for this one

    Any input is appreciated

  • wannalearn (11/15/2010)


    DELETE ABCDEF FROM dbo.XYZ

    WHERE Column = 'ABCDEF100'

    Where are you getting DELETE ABCDEF ? Look in BOL for the basic format of a DELETE statement. It should follow the format that I showed you above....

    DELETE t

    FROM dbo.XYZ t

    WHERE Column = 'ABCDEF100'

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • wannalearn (11/15/2010)


    Thank you for your reply. Per your advice,

    I created

    DELETE ABCDEF FROM dbo.XYZ

    WHERE Column = 'ABCDEF100'

    want to delete ABCDEF AND LEAVE 100 IN THAT COLUMN

    Plz help me create statement for this one

    Any input is appreciated

    Then you want to do an UPDATE, not a DELETE.....DELETE will remove the row from the database.....UPDATE will change the value of a column.

    UPDATE dbo.XYZ

    SET Column = 'ABCDEF'

    WHERE Column = 'ABCDEF100'

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • wannalearn (11/15/2010)


    Thank you for your reply. Per your advice,

    I created

    DELETE ABCDEF FROM dbo.XYZ

    WHERE Column = 'ABCDEF100'

    want to delete ABCDEF AND LEAVE 100 IN THAT COLUMN

    Plz help me create statement for this one

    Any input is appreciated

    What RDBMS did you originally learn to write SQL in (I mean that seriously, not snidely, very odd format)? That's a propietary method if it works at all.

    You want UPDATE, not DELETE. UPDATE changes values in an existing row, DELETE removes the row entirely. So, You want something along the lines of:

    UPDATE table

    SET Column = '100'

    WHERE Column = 'ABCDEF'


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Thank you for your input.

    I want to update in SQL. Your advice worked but only one row is affected from it. If I want to update all records in that field. How do i do it?

  • Are all the rows getting the same update? If so, modify the Where clause to include all the rows you want.

    If not, what are some sample rows?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Yes, I just have to remove ABCDEF and leave integer in that column. all records have ABCDEF.... ( similar values) in that table.

    UPDATE TABLE

    SET COLUMN = '0...' (THIS AREA)

    WHERE COLUMN = 'ABCDEF...'(THIS AREA)

    What should I do in this area or value section to update all records in that column?

    Thanks

  • My previous example updated the wrong part of the column...thanks to Craig for doing it correctly.

    DECLARE @Table TABLE (Val varchar(100))

    INSERT INTO @Table

    SELECT 'ABCDEF100' UNION ALL

    SELECT 'ABCDEF200' UNION ALL

    SELECT 'ABCDEF300'

    SELECT * FROM@Table

    UPDATE @Table

    SET Val = SUBSTRING(Val, 7, LEN(Val))

    WHERELEFT(Val,6) = 'ABCDEF'

    SELECT * FROM@Table

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • sample rows as you requested

    XYZ

    ABCDEF1010

    ABCDEF1012

    ABCDEF102

    ABCDEF1026

    ABCDEF1030

    ABCDEF1032

    ABCDEF1044

  • Update dbo.MyTable

    set Column = replace(Column, 'ABCDEF', '')

    where Column like 'ABCDEF%';

    Does that get what you need?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • sample rows as you requested

    XYZ

    ABCDEF1010

    ABCDEF1012

    ABCDEF102

    ABCDEF1026

    ABCDEF1030

    ABCDEF1032

    ABCDEF1044

  • Thank you so much..

    It worked.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic. Login to reply