Professional Web Applications Themes

Insert Bln into new column? - ASP Database

How does one execute a one time INSERT query inside the data window of a particular table for all records >1... The table has referential integrity on StateID...here is my stab but I am picking up a SYNTAX ERROR near 'Begin': IF (SELECT StateID FROM State WHERE StateID > 0) BEGIN (INSERT INTO State(StateBln) VALUES (1) WHERE StateID > 0) END The query needs to deposit the Int value (1) into newly created column StateBln... Thanks Jason...

Sponsored Links
  1. #1

    Default Insert Bln into new column?

    How does one execute a one time INSERT query inside the data window of a
    particular table for all records >1...

    The table has referential integrity on StateID...here is my stab but I am
    picking up a SYNTAX ERROR near 'Begin':


    IF (SELECT StateID
    FROM State
    WHERE StateID > 0) BEGIN
    (INSERT
    INTO State(StateBln)
    VALUES (1)
    WHERE StateID > 0) END

    The query needs to deposit the Int value (1) into newly created column
    StateBln...

    Thanks
    Jason


    Sponsored Links
    Guest

  2. #2

    Default Re: Insert Bln into new column?

    com wrote: 
    You can't use WHERE with VALUES. What are you trying to do? Insert a new
    record? If so, you don't need a WHERE clause do you? Or are you trying to
    update an existing record? If so, you need to use an UPDATE statement, not
    an INSERT.

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Guest

  3. #3

    Default Re: Insert Bln into new column?

    Damn, I'm stupid....too little sleep is my excuse! This works:

    UPDATE State
    SET StateBln = '1'
    WHERE (StateID > 0)

    Many thanks Bob
    Jason
    "Bob Barrows [MVP]" <SPAMcom> wrote in message
    news:phx.gbl... 
    > You can't use WHERE with VALUES. What are you trying to do? Insert a new
    > record? If so, you don't need a WHERE clause do you? Or are you trying to
    > update an existing record? If so, you need to use an UPDATE statement, not
    > an INSERT.
    >
    > Bob Barrows
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"
    >
    >[/ref]


    Guest

  4. #4

    Default Re: Insert Bln into new column?

    On Fri, 13 Aug 2004 12:11:02 -0400, <com> wrote:
     


    You could do the following as well if a row doesn't exist in a table
    then add a new row or update an existing one.


    IF EXISTS(SELECT StateID FROM State WHERE StateID > 0)
    BEGIN
    UPDATE State SET StateBln='1' WHERE StateID>0
    -- Some Error checking code here
    END
    ELSE
    BEGIN
    INSERT INTO State(StateBln) VALUES('1')
    -- Some Error checking code here
    END


    Also please don't top post on usenet.


    HTH

    Al

     
    >> You can't use WHERE with VALUES. What are you trying to do? Insert a new
    >> record? If so, you don't need a WHERE clause do you? Or are you trying to
    >> update an existing record? If so, you need to use an UPDATE statement, not
    >> an INSERT.
    >>
    >> Bob Barrows
    >> --
    >> Microsoft MVP - ASP/ASP.NET
    >> Please reply to the newsgroup. This email account is my spam trap so I
    >> don't check it very often. If you must reply off-line, then remove the
    >> "NO SPAM"
    >>
    >>[/ref]
    >[/ref]

    Harag Guest

  5. #5

    Default Re: Insert Bln into new column?

    Awesome!!! many thanks.

    ps: 'Top post' ? Not sure what this means....?

    -Jason
    "Harag" <net> wrote in message
    news:com... 
    >
    >
    > You could do the following as well if a row doesn't exist in a table
    > then add a new row or update an existing one.
    >
    >
    > IF EXISTS(SELECT StateID FROM State WHERE StateID > 0)
    > BEGIN
    > UPDATE State SET StateBln='1' WHERE StateID>0
    > -- Some Error checking code here
    > END
    > ELSE
    > BEGIN
    > INSERT INTO State(StateBln) VALUES('1')
    > -- Some Error checking code here
    > END
    >
    >
    > Also please don't top post on usenet.
    >
    >
    > HTH
    >
    > Al
    >
    > [/ref][/ref]
    column [/ref][/ref]
    new [/ref][/ref]
    to [/ref][/ref]
    not 
    > >[/ref]
    >[/ref]


    Guest

  6. #6

    Default Re: Insert Bln into new column?

    On Fri, 13 Aug 2004 14:08:54 -0400, <com> wrote:
     


    No probs. :)

     


    Top Post is exactly this posting at the very top of all the replies
    rather than posting below what your actually replying to.

    Personally I don't mind it (saves me scrolling down) as I read this
    using a offline browser and but a lot of people mind. so I've now
    started not to top post as well.

    HTH

    Al.

     
    >>
    >>
    >> You could do the following as well if a row doesn't exist in a table
    >> then add a new row or update an existing one.
    >>
    >>
    >> IF EXISTS(SELECT StateID FROM State WHERE StateID > 0)
    >> BEGIN
    >> UPDATE State SET StateBln='1' WHERE StateID>0
    >> -- Some Error checking code here
    >> END
    >> ELSE
    >> BEGIN
    >> INSERT INTO State(StateBln) VALUES('1')
    >> -- Some Error checking code here
    >> END
    >>
    >>
    >> Also please don't top post on usenet.
    >>
    >>
    >> HTH
    >>
    >> Al
    >>
    >> [/ref]
    >column [/ref]
    >new [/ref]
    >to [/ref]
    >not 
    >>[/ref]
    >[/ref]

    Harag Guest

  7. #7

    Default Re: Insert Bln into new column?

    On Fri, 13 Aug 2004 14:08:54 -0400, <com> wrote:
     

    just found this url that might exaplain it better than I did:

    http://www.caliburn.nl/topposting.html

    HTH

    Al

     
    >>
    >>
    >> You could do the following as well if a row doesn't exist in a table
    >> then add a new row or update an existing one.
    >>
    >>
    >> IF EXISTS(SELECT StateID FROM State WHERE StateID > 0)
    >> BEGIN
    >> UPDATE State SET StateBln='1' WHERE StateID>0
    >> -- Some Error checking code here
    >> END
    >> ELSE
    >> BEGIN
    >> INSERT INTO State(StateBln) VALUES('1')
    >> -- Some Error checking code here
    >> END
    >>
    >>
    >> Also please don't top post on usenet.
    >>
    >>
    >> HTH
    >>
    >> Al
    >>
    >> [/ref]
    >column [/ref]
    >new [/ref]
    >to [/ref]
    >not 
    >>[/ref]
    >[/ref]

    Harag Guest

  8. #8

    Default Re: Insert Bln into new column?

    Got it thanks!


    Guest

Similar Threads

  1. INSERT file to column
    By HugoSchmidt in forum Coldfusion Database Access
    Replies: 5
    Last Post: March 14th, 05:47 PM
  2. Select after insert to the unique column
    By Bruno Wolff III in forum PostgreSQL / PGSQL
    Replies: 3
    Last Post: December 13th, 04:44 PM
  3. insert a hyperlink column to datgrid
    By TJS in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: March 2nd, 02:59 PM
  4. Have server get value for column on Insert?
    By Ian Boyd in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: June 30th, 06:42 PM
  5. Which is the best column to insert index...
    By fabriZio in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: June 30th, 02:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139