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
 Query Entering Data into table?

Author  Topic 

Dirtsnap
Starting Member

1 Post

Posted - 2009-06-09 : 20:52:31
Hey guys,

i am currently making like a database for a gym (project for school). and i want it to be able to be able to make up workout routines for people. I have heaps of exercises in a table already, and have each one assigned to like where the exercise works, eg Legs, chest, back, arms, etc.

What i want to do is make a query which chooses one exercise of each type, and make it enter that into a table. I know how to make it randomally pick the exercises, just have no idea how to get it to enter the data back into a "Workout Program" table.

any ideas?

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2009-06-09 : 21:19:57
Take a look at this and see if it is what you are looking for.

declare @BodyPart table(PartId int Identity(1,1),Part varchar(50))
declare @Workout table(WorkoutId int Identity(1,1) ,PartID int,Workout varchar(50))
insert into @BodyPart(Part)
select 'Arms' Union All
select 'Back' Union All
select 'Chest' Union All
select 'Legs'

insert into @Workout(PartID,Workout)
select 1,'Curls' Union All
select 1,'Tricep Extensions' Union All
select 2,'Military Press' Union All
select 2,'Shoulder Shrugs' Union All
select 3,'Push Ups' Union All
select 3,'Bench Press' Union All
select 4,'Leg Press' Union All
select 4,'Squats'

Select a.Part,b.Workout
from
@BodyPart a
Inner Join
(
Select Row_Number() over ( Partition by PartID order by newid()) as rowID,*
from
@Workout
) b
on a.PartID = b.PartID
where b.RowID = 1



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-10 : 02:30:44
is this u want dirtsnap,
try this one
SELECT part,(SELECT TOP 1 workout FROM @workout WHERE a.partid = partid)
FROM @bodypart a
Go to Top of Page
   

- Advertisement -