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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 I need a simple search query

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, TimesRedirected

I 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 it
Otherwise, 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]

Go to Top of Page

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.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-01-13 : 22:13:38
Select LinkURL
FROM [Table]
Where LinkURL = yoursearchURL


you can do this in a procedure and pass the required URL

Create pFindURLinTable (@myURL varchar(20))
as

SET @mySearch = @myURL

Select LinkURL
FROM [Table]
Where LinkURL = @mySearch



For example...



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

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)
END

RETURN
Go to Top of Page

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)
END

RETURN



Try like this and see if it works.
Go to Top of Page

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)
END

RETURN



Note that your query wont return NULL value if there is no data for the serached value. Instead use not exists as suggested

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -