Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InsertCommand

Status
Not open for further replies.

mana2

Programmer
Aug 9, 2002
116
0
0
US
Hi,

Is it possible to have an if or case type statement in the SelectCommand in Formview?

I have a combobox and if the item doesn't exit I need to add it to the lookup table and then if it does exist, I need to just insert the value into the main table.

So it would be something like this:

InsertCommand="
INSERT INTO [Category] (CategoryName)
SELECT DISTINCT @Category as CategoryName FROM Category
WHERE @Category NOT In (select CategoryName from Category)
SET @CategoryID = SCOPE_IDENTITY();

2nd condition would be:

SELECT @Category as CategoryName FROM Category
WHERE EXISTS (select CategoryName from Category)
SET @CategoryID = @Category;

Both conditions:
INSERT INTO [Product] ([Category]) VALUES (@CategoryID) "

Thanks so much
 
the select command is just text and as such you can preform any tsql action the backing database supports.

however I would strongly caution against melding read and write sql statements into a single operation. it would be better to keep these as separate, unique commands.


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top