Solved

comparing

Posted on 2008-10-21
19
157 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

24 Experts available now in Live!

Get 1:1 Help Now