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
 General SQL Server Forums
 New to SQL Server Programming
 how to pass numeric value

Author  Topic 

nisar
Starting Member

29 Posts

Posted - 2008-12-21 : 22:04:41
Hi i m having problem in executing this query
can anyone solver this value of @sectionid = 6000

it is numeric value but it is passing as varchar
if i make comment this statement

' and w.sectionid = '''+@sectionid+''''+

then this query
work other wise give syntax error



set @sql = 'select distinct '+@fields+' from dbo.tbl_workorderparts p (nolock, index(0)) '+ ' left join dbo.tbl_workorder w (nolock, index(0)) '+ ' left join dbo.tbl_xhfiwebdetail d (nolock, index(0)) on d.bbramsid = w.bbramsid '+ @forcat_sql +
' left join dbo.tbl_itemprocessref p1 (nolock, index(0)) on p1.itemprocessuid = w.itemprocesstypeid '+
' left join dbo.tbl_itemprocessref p2 (nolock, index(0)) on p2.itemprocessuid = w.itemprocessuid '+
' left join dbo.tbl_positionref s (nolock, index(0)) on s.positionuid = w.sectionid '+
' left join dbo.tbl_itemprocessref p3 (nolock, index(0)) on p3.itemprocessuid = w.status '+
' on w.workorderid = p.workorderid '+
' left join dbo.tbl_tric2005 t (nolock, index(0)) '+
' left join dbo.sut_trictransaction tt (nolock, index(0)) on tt.sut_bbramstrackid = cast(t.id as varchar(32)) '+
' on p.workorderpartid = t.workorderpartid '+
' where p.workorderpartid is not null '+



' and w.sectionid = '''+@sectionid+''''+



' and t.dept = '+@tempdept+
' and t.dateapproved is null and t.approvingofficial is null'+
' and p.orderedby <> '+ @templogin1

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-21 : 22:57:26
Why are you using dynamic SQL for this?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2008-12-22 : 01:29:07
why not use store procedures? You got @ variables, and using store procedures seems to be a better option.

Anyway to solve it, remove the ' ' between the values
and w.sectionid = "+@sectionid+"+

and it will be a numberic type instead of a string.

check out my blog at http://www.aquariumlore.blogspot.com
Go to Top of Page

nisar
Starting Member

29 Posts

Posted - 2008-12-22 : 01:47:37
Thanks it works for me
Go to Top of Page
   

- Advertisement -