Link to home
Start Free TrialLog in
Avatar of mattibutt
mattibuttFlag for United States of America

asked on

comparing

hi
i want to select items from the table one, i am selecting videoitems from the table
i wanna write a query where
@videoitemid is not equal to @tracking
Avatar of brad2575
brad2575
Flag of United States of America image

select from tableOne where videoitems <> tracking
sorry forgot the field list

select * from tableOne where videoitems <> tracking
Try this:

SELECT videoitem
FROM [tablename]
WHERE @videoitemid <> @tracking

[tablename] is name of your table

eridanix
Avatar of mattibutt

ASKER

i dont know for reason this query isnt working
WHERE @videoitemid <> @tracking
Are you trying to do a comparrison where variables do not equal?  Or do you want to compare the values in the table?  The where clause you have is comparing variables and NOT the data in the table:

variables
WHERE @videoitemid <> @tracking

vs table comparrison
WHERE videoitemid <> tracking
this is how i am doing in the procedure
select @Tracking = VideoItemID from DayCounting where userid = @UserID
Declare @Tracking int
WHERE @videoitemid <> @tracking
i want to compare data
It should by something like:

DECLARE @Tracking INT
DECLARE @userId INT

SELECT VideoItemId
FROM DayCounting
WHERE userid = @UserID AND videoItemId <> @userId

You must delclare all variables, which you want to use in stored procedure.
If @userId is not INT, so use right type for it.
I am selecting from videoitems table but i want to make sure it doesnt exist in daycounting table
everything is declared and everything works but it doesnt work on the basis of userid i have been trying different approaches
this is how i currently done it and it works
LEFT JOIN DayCounting DD  
       ON VI.[VideoItemID] = DD.[VideoItemID]       
AND DD.[VideoItemID]  is null       

however when i want to add the userid condition as well it fuck up everything
LEFT JOIN DayCounting DD -- to see how many slots passed since this segment was selected  
       ON VI.[VideoItemID] = DD.[VideoItemID]

i dont know wat is possibly going wrong
OK, then you must use both tables in your sql query.
I don't knou how your tables looks like.
Can you describe, how your table looks like (fields and theit types)?



LEFT JOIN DayCounting DD  
       ON VI.[VideoItemID] = DD.[VideoItemID]      
AND DD.[VideoItemID]  is null      

if userid is in VideoItemId table then ad to the end of query this:
WHERE VI.userId <> @UserID

if userid is in DayCounting table then ad to the end of query this:
WHERE DD.userId <> @UserID
its causing the same problem basically its selecting the same item many times i dont get it its really frustrating


video item ids
27660
28443
28288
28781
28782
28313
28293
28295
28801
28307
28310
28808
28809
28504
28830
28830
28824
28844
28844
28844
28842
28845
28845
28841
28843
27799
28738
28850
28848
28848
28849
28849
28849
28851
28851
28853
28132
28062
28814
28814
28810
28815

Open in new window

Try to use INNER JOIN insted of LEFT JOIN
or use GROUP BY VI.[VideoItemID] at the end of query.
still doesnt work
Can you describe, how your table looks like (fields and their types)?
hi eridanix

i have changed my approach the way i was tackling this problem, i have created another table DayCountingRun and then copy values into this table by using following command
insert into DayCountingRun
select *
from DayCounting
where Userid = @Userid

then used the join
LEFT JOIN DayCountingRun DD  
       ON VI.[VideoItemID] = DD.[VideoItemID]      
AND DD.[VideoItemID]  is null  


this soloutions only work if i still keep the following statement in the procedure


in the end i empty the table using following command
DELETE FROM DayCountingRun

seems to me right now this soloution is working fine
if i dont have the belowstatement in my procedure then it behaves wrongly
INSERT DayCountingRun Values(@sVideoItemID,1,@userid,@SlotStartTime,@Rating)
 so i have one more question regards to this
does procedure execute sequentially i mean line number 1 will be executed before line 2 etc
ASKER CERTIFIED SOLUTION
Avatar of eridanix
eridanix
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thankx buddy