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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to convert varchar to int in sql..
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 12/14/2012 :  00:07:07  Show Profile  Reply with Quote
sql query
select AuditCategoryName from IS_AuditCategory where AuditCategoryId in(select CheckListCategoryIds from IS_AuditChecklistProjectScope where IS_AuditChecklistProjectScope.[PrimaryProjectScopeId ] =2)

Conversion failed when converting the varchar value '46,48,43,45,44' to data type int.


Flowing Fount of Yak Knowledge

2242 Posts

Posted - 12/14/2012 :  00:39:59  Show Profile  Reply with Quote
Try this...

select AuditCategoryName 
from IS_AuditCategory t1
JOIN (select CheckListCategoryIds 
		from IS_AuditChecklistProjectScope 
		where IS_AuditChecklistProjectScope.[PrimaryProjectScopeId]=2
ON ','+CheckListCategoryIds+',' LIKE '%,'+CAST(AuditCategoryId as varchar(30))+',%'

Let me know the result

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/14/2012 :  02:32:37  Show Profile  Reply with Quote
or use a string parsing UDF to get values onto a table and then join to that

DECLARE @CategoryIDs varchar(8000)

select @CategoryIDs=CheckListCategoryIds 
		from IS_AuditChecklistProjectScope 
		where IS_AuditChecklistProjectScope.[PrimaryProjectScopeId]=2

select AuditCategoryName 
from IS_AuditCategory t1
JOIN dbo.ParseValues(@CategoryIDs,',') f
ON f.Val = t1.AuditCategoryId 

ParseValues can be found in below link

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000