Hi All,I was told I would need to make a temp table in order to make this work. I have not yet had the need for a temp table, and in the past I've heard of performace issues, so I always tried to stay away.I'll describe what I have and what results I need. My main question is how can this be done with sprocs and/or functions. I hope I don't need to use temp tables, but if I have to, I will.BTW: I'm using MS SQL Server 2008Table:create table [dbo].[users][userid] [int] identity(1,1) not null,[username] [varchar](255) not null,constraint [pk_users] primary key clusteredcreate table [dbo].[links][linkid] [int] identity(1,1) not null,[linkname] [varchar](255) not null,constraint [pk_links] primary key clusteredcreate table [dbo].[userlinks][userid] [int] not null,[linkid] [int] not null,[repeat] [int] not nullcreate procedure [dbo].[sp_GetLinks]@userid intasbeginset nocount on;--here i need to be able to add one to the repeat or add to the table if doesn't exist--plus i don't know how to add one to repeat for each row selectedselect top 10 *from linkswhere linkid not in ( select top 10 ul.linkid from userlinks ul where ul.userid = @userid order by ul.repeat desc )order by (newid())end
Users holds a list of registered users, while links are a list of about 1000 links we add. The idea is that the sproc should return 10 random links. These random links must not be any that have been return yet, and inserted into the userlinks table with the userid, linkid and a "repeat = 1". Obviously at some point all the links would have been returned, so then the goal is to return any 10 links and update the userlinks table and one to the repeat.I am open to redesigning the db design if there is a better way to accomplish this.Thank you in advance.- RoLY roLLshttp://www.buysellmotors.comhttp://www.tikiloveroom.comhttp://www.rolyrolls.comhttp://iphone.rolyrolls.com