Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Apples
Posting Yak Master
146 Posts |
Posted - 2008-01-13 : 22:06:00
|
| I have a table that has these columns:LinkID, LinkURL, TimesRedirectedI have a webpage that keeps track of the url's of where the users are coming from. When they redirect to the page, the page will:If the url of the previous page isn't in the database, add itOtherwise, add to the TimesRedirected column. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-13 : 22:08:16
|
Sorry . . . . what is your question ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Apples
Posting Yak Master
146 Posts |
Posted - 2008-01-13 : 22:10:25
|
| Haha, sorry, I'll try to be more specific.LinkURL is a string of a url.Given a url, I just need to check and see if it is in the table. |
 |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2008-01-13 : 22:13:38
|
Select LinkURLFROM [Table]Where LinkURL = yoursearchURLyou can do this in a procedure and pass the required URLCreate pFindURLinTable (@myURL varchar(20))asSET @mySearch = @myURLSelect LinkURLFROM [Table]Where LinkURL = @mySearchFor example... Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
Apples
Posting Yak Master
146 Posts |
Posted - 2008-01-13 : 23:22:27
|
OK, I created a stored procedure, and for some reason it's not working. Can someone take a look at this?ALTER PROCEDURE sproc_UpdateLinks ( @url varchar(50) ) AS IF(SELECT LinkURL FROM tblLinks WHERE @url = LinkURL) IS NULL BEGIN INSERT INTO tblLinks (LinkURL) VALUES(@url) ENDRETURN |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-13 : 23:56:56
|
quote: Originally posted by Apples OK, I created a stored procedure, and for some reason it's not working. Can someone take a look at this?ALTER PROCEDURE sproc_UpdateLinks ( @url varchar(50) ) AS IF NOT EXISTS(SELECT LinkURL FROM tblLinks WHERE @url = LinkURL) BEGIN INSERT INTO tblLinks (LinkURL) VALUES(@url) ENDRETURN
Try like this and see if it works. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-14 : 01:04:45
|
quote: Originally posted by Apples OK, I created a stored procedure, and for some reason it's not working. Can someone take a look at this?ALTER PROCEDURE sproc_UpdateLinks ( @url varchar(50) ) AS IF(SELECT LinkURL FROM tblLinks WHERE @url = LinkURL) IS NULL BEGIN INSERT INTO tblLinks (LinkURL) VALUES(@url) ENDRETURN
Note that your query wont return NULL value if there is no data for the serached value. Instead use not exists as suggestedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|