Solved

comparing

Posted on 2008-10-21
19
146 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now