Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL Server string comparsion issue

Author  Topic 

pervaiz
Starting Member

3 Posts

Posted - 2010-11-11 : 02:29:30
Hi,

I have two strings "New York airport jets 'directed by child' New York's JFK airport. File photo US officials are investigating how a child was apparently allowed to direct planes at New York's JFK airport - one of the country's busiest." and "New York airport jets 'directed by child' New York's JFK airport. File photo US officials are investigating how a child was apparently allowed to direct planes at New York's JFK airport - one of the country's busiest." that are actually retrieved from DB. I have to compare them because it is my project requirement.They seem to be equal and even KDiff(File Comparison Tool)show they are equal. But SQL query shows they are different. Index of difference is 43. I have tried both '!=' and '<>' operators. Any help?

Thanks,
Pervaiz

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-11 : 02:53:38
In sql how you are doing comparision ?
Are you storing the values in a variable and comparing it ?
Go to Top of Page

pervaiz
Starting Member

3 Posts

Posted - 2010-11-11 : 03:02:31
Thanks for reply.
I am storing data in temporary tables and then applying checks. I have to do that because I have to apply some other checks and union the result.
Following is my actual query:

SELECT #ChildAnswers.QuestionName,#ParentAnswers.BigAnswer AS 'ParentValue',#ChildAnswers.BigAnswer AS 'ChildValue' FROM #ParentAnswers INNER JOIN #ChildAnswers ON #ParentAnswers.QuestionId=#ChildAnswers.QuestionId
WHERE #ParentAnswers.BigAnswer != #ChildAnswers.BigAnswer
Please note that I also tried with '<>'.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-11 : 04:02:06
quote:
Originally posted by pervaiz

Thanks for reply.
I am storing data in temporary tables and then applying checks. I have to do that because I have to apply some other checks and union the result.
Following is my actual query:

SELECT #ChildAnswers.QuestionName,#ParentAnswers.BigAnswer AS 'ParentValue',#ChildAnswers.BigAnswer AS 'ChildValue' FROM #ParentAnswers INNER JOIN #ChildAnswers ON #ParentAnswers.QuestionId=#ChildAnswers.QuestionId
WHERE #ParentAnswers.BigAnswer != #ChildAnswers.BigAnswer
Please note that I also tried with '<>'.



#ParentAnswers is temp table. Are you creating the structure of temp table initially or creating it in select statement.

Can you provide some sample data
Go to Top of Page

pervaiz
Starting Member

3 Posts

Posted - 2010-11-11 : 04:43:45
I am creating temp table in select statement.

Select BigAnswer,QuestionName,QuestionId into #ParentAnswers
FROM V_Checklist
WHERE ChecklistId =@ParentChecklist

Select BigAnswer,QuestionName,QuestionId into #ChildAnswers
FROM V_Checklist
WHERE ChecklistId =@ChildChecklist


SELECT #ChildAnswers.QuestionName,#ParentAnswers.BigAnswer AS 'ParentValue',#ChildAnswers.BigAnswer AS 'ChildValue' FROM #ParentAnswers INNER JOIN #ChildAnswers ON #ParentAnswers.QuestionId=#ChildAnswers.QuestionId
WHERE #ParentAnswers.BigAnswer != #ChildAnswers.BigAnswer

Following is the data for #ParentAnswers
QuestionId QuestionName BigAnswer
12995 PCB Layout Group 1: New York airport jets 'directed by child' New York's JFK airport. File photo US officials are investigating how a child was apparently allowed to direct planes at New York's JFK airport - one of the country's busiest.


12996 PCB Layout Group 2: New York airport jets 'directed by child' New York's JFK airport. File photo US officials are investigating how a child was apparently allowed to direct planes at New York's JFK airport - one of the country's busiest.

and for #ChildAnswers

QuestionId QuestionName BigAnswer
12995 PCB Layout Group 1: New York airport jets 'directed by child' New York's JFK airport. File photo US officials are investigating how a child was apparently allowed to direct planes at New York's JFK airport - one of the country's busiest.

12996 PCB Layout Group 2: New York airport jets 'directed by child' New York's JFK airport. File photo US officials are investigating how a child was apparently allowed to direct planes at New York's JFK airport - one of the country's busiest.

Basically, both tables have same data here. I need to fetch data only if both tables have different BigAnswers. In my case it should return nothing but it treats them as they are different.
Go to Top of Page
   

- Advertisement -