Solved

comparing

Posted on 2008-10-21
19
185 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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