Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 28th, 2005, 01:24 AM
kelvinlim11 kelvinlim11 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 123 kelvinlim11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 2 m 8 sec
Reputation Power: 0
any1 knows how to code it.

lets say now i have a SELECT statement tat chooses a number back based on a condition...

say mayb the number is SNO.. if there is such an number(does not matter wat is the number)

then i wan to do sumthing say task A.
if there is no SNO tat match the condition... then i wana to do TASK B

how can i use if else to code it?

wat does the database return to my asp page?

Reply With Quote
  #2  
Old January 28th, 2005, 01:42 AM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 8
Depends on what the task A and B are. Do you want to do these "tasks" within a SQL statement or within code. For some "tasks", it is not possible (or inefficient) to do it in SQL and you may need to do it in your application code (ASP).
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.

Reply With Quote
  #3  
Old January 28th, 2005, 02:21 AM
kelvinlim11 kelvinlim11 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 123 kelvinlim11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 2 m 8 sec
Reputation Power: 0
hmm..

ok let me describe u the prob...

i wana to prevent a duplicate insertion of a tuple.

but i need to know b4 i insert another tuple if there is 1 tat is already inside...

i know its quite dumb cos it is not suppose to store duplicate but trust me... this prob is too much too tink logically...

so i will do a search and find... if yes then i will stop the insertion and mayb link to an error page...

if no such tuple then i will insert the new tuple

how?

Reply With Quote
  #4  
Old January 28th, 2005, 02:26 AM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 8
Ok, this can be done in a SQL statement then
Code:
IF NOT EXISTS (
   SELECT   field1
   FROM      tablename
   WHERE    field1 = value1
   AND        field2 = value2
)
BEGIN
   INSERT INTO tablename (field1, field2, field3)
   VALUES (value1, value2, value3)
END


The other way is to exploit the "Easier to ask forgiveness than permission" principle. You can create a unique index on the field names. Then try inserting a row directly. If the insert fails, simply suppress the error message on your application and proceed as though nothing happened .

Last edited by Scorpions4ever : January 28th, 2005 at 02:30 AM.

Reply With Quote
  #5  
Old January 28th, 2005, 02:40 AM
kelvinlim11 kelvinlim11 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 123 kelvinlim11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 2 m 8 sec
Reputation Power: 0
thks but sori

sori pal...

i am rather new to all this and i have no idea how i shd insert the above code into my asp page

i have set up the connection string but still i dun realli understand

can u help?

Reply With Quote
  #6  
Old January 29th, 2005, 08:07 PM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 8
You should really get a book and study the basics of how to execute SQL statements yourself. That is the best way to do it. You already know how to make a database connection. The next thing to read about is how to execute SQL statements.

Reply With Quote
  #7  
Old January 29th, 2005, 08:48 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
You could do it very easy, like this

Create a stored procedure in SQL Server
Code:
Create Procedure stp_MyProcedure
   @value1 As datatype,
   @value2 As datatype,
   @value3 As datatype
As
IF NOT EXISTS (
   SELECT   field1
   FROM      tablename
   WHERE    field1 = @value1
   AND        field2 = @value2
)
BEGIN
   INSERT INTO tablename (field1, field2, field3)
   VALUES (@value1, @value2, @value3)
END


Then on the asp page.
Code:
value1 = Request.Form("Field1")
value2 = Request.Form("Field2")
value3 = Request.Form("Field3")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Your ConnectionString"

This assumes the 3 values are strings.
Conn.Execute("Exec stp_MyProcedure @value1 = '" & value1 & "', @value2 = '" & value2 & "', @value3 = '" & value3 & "'")

Conn.Close
Set Conn = Nothing

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > any1 knows how to code it.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT