Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Conditional Stored Procedure

New Here ,
Nov 30, 2006 Nov 30, 2006
how can i run an update procedure only if 2 fields values already exist, in which case i would run an insert procedure?
i am using asp vbscript
something like .....
if field1 = value1
and field2 = value2
then
update......
else
insert.....
TOPICS
Server side applications
399
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2006 Nov 30, 2006

>something like .....

Yes, exactly like that...

if field1 = value1 and field2 = value2
then
Perform update
else
Perform insert
end if

Cheers,
Rob
http://robgt.com/ [Tutorials and Extensions]
Firebox stuff: http://robgt.com/firebox
Skype stuff: http://robgt.com/skype
SatNav stuff: http://robgt.com/satnav



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2006 Nov 30, 2006
i tried the code but for some reason it will actually only do the insert procedure.
could you show me an example of the markup? here is what mine looks like...

<% If "&(Inv_total)&" = "0" Then %>
<%
set Insert = Server.CreateObject("ADODB.Command")
Insert.ActiveConnection = MM_Inv_STRING
Insert.CommandText = "INSERT INTO Inv (Date, ID, Count) VALUES ( date, url parameter , 1) "
Insert.CommandType = 1
Insert.CommandTimeout = 0
Insert.Prepared = true
Insert.Execute()
%>
<% ElseIf "&(Inv_total)&" > "1" Then %>
<%
set Update = Server.CreateObject("ADODB.Command")
Update.ActiveConnection = MM_Inv_STRING
Update.CommandText = "UPDATE Inv SET Count = Count +1 WHERE Inv.ID = "url parameter"
Update.CommandType = 1
Update.CommandTimeout = 0
Update.Prepared = true
Update.Execute()
%>
<% End If %>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2006 Nov 30, 2006
LATEST
nevermind man,

i just enclosed the dynamic field Inv_Total in the "& &" and when i took it out it worked..
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2006 Nov 30, 2006
Ouch, dude. That's total gibberish. Also, you don't write mark-up to do an
insert; you write a server script (or "code" to be super generic). Markup
is what you used to make the form.

Anyway:
<%
If Inv_total = 0 Then
set Insert = Server.CreateObject("ADODB.Command")
Insert.ActiveConnection = MM_Inv_STRING
Insert.CommandText = "INSERT INTO Inv (Date, ID, Count) VALUES ( date,
" & urlparameter & " , 1) "
Insert.CommandType = 1
Insert.CommandTimeout = 0
Insert.Prepared = true
Insert.Execute()
ElseIf Inv_total > 1 Then
set Update = Server.CreateObject("ADODB.Command")
Update.ActiveConnection = MM_Inv_STRING
Update.CommandText = "UPDATE Inv SET Count = Count +1 WHERE Inv.ID = "
& urlparameter
Update.CommandType = 1
Update.CommandTimeout = 0
Update.Prepared = true
Update.Execute()
End If
%>



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines