Groups | Blog | Home
all groups > inetserver asp db > august 2004 >

inetserver asp db : Insert Bln into new column?



jason NO[at]SPAM catamaranco.com
8/13/2004 11:50:15 AM
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

Bob Barrows [MVP]
8/13/2004 11:59:52 AM
[quoted text, click to view]
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"

jason NO[at]SPAM catamaranco.com
8/13/2004 12:11:02 PM
Damn, I'm stupid....too little sleep is my excuse! This works:

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

Many thanks Bob
Jason
[quoted text, click to view]

jason NO[at]SPAM catamaranco.com
8/13/2004 2:08:54 PM
Awesome!!! many thanks.

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

-Jason
[quoted text, click to view]

jason NO[at]SPAM catamaranco.com
8/13/2004 4:07:54 PM
Got it thanks!

Harag
8/13/2004 6:57:05 PM
[quoted text, click to view]


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


[quoted text, click to view]
Harag
8/13/2004 8:04:49 PM
[quoted text, click to view]


No probs. :)


[quoted text, click to view]


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.


[quoted text, click to view]
Harag
8/13/2004 8:07:59 PM
[quoted text, click to view]

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

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

HTH

Al


[quoted text, click to view]
AddThis Social Bookmark Button