?
Solved

comparing

Posted on 2008-10-21
19
Medium Priority
?
186 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:mattibutt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 3
19 Comments
 
LVL 16

Expert Comment

by:brad2575
ID: 22766944
select from tableOne where videoitems <> tracking
0
 
LVL 16

Expert Comment

by:brad2575
ID: 22766950
sorry forgot the field list

select * from tableOne where videoitems <> tracking
0
 
LVL 5

Expert Comment

by:eridanix
ID: 22766980
Try this:

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

[tablename] is name of your table

eridanix
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 11

Author Comment

by:mattibutt
ID: 22767354
i dont know for reason this query isnt working
WHERE @videoitemid <> @tracking
0
 
LVL 16

Expert Comment

by:brad2575
ID: 22767376
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
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22767454
this is how i am doing in the procedure
select @Tracking = VideoItemID from DayCounting where userid = @UserID
Declare @Tracking int
WHERE @videoitemid <> @tracking
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22767539
i want to compare data
0
 
LVL 5

Expert Comment

by:eridanix
ID: 22767656
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.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22767710
I am selecting from videoitems table but i want to make sure it doesnt exist in daycounting table
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22767745
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
0
 
LVL 5

Expert Comment

by:eridanix
ID: 22767787
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)?

0
 
LVL 5

Expert Comment

by:eridanix
ID: 22767906


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
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22768037
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

0
 
LVL 5

Expert Comment

by:eridanix
ID: 22768122
Try to use INNER JOIN insted of LEFT JOIN
or use GROUP BY VI.[VideoItemID] at the end of query.
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22768518
still doesnt work
0
 
LVL 5

Expert Comment

by:eridanix
ID: 22769257
Can you describe, how your table looks like (fields and their types)?
0
 
LVL 11

Author Comment

by:mattibutt
ID: 22775656
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
0
 
LVL 5

Accepted Solution

by:
eridanix earned 2000 total points
ID: 22784112
Hi mattibutt,

yes, stored procedure execute queries sequentially.
0
 
LVL 11

Author Closing Comment

by:mattibutt
ID: 31508256
thankx buddy
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question