troubleshooting Question

sql server query

Avatar of dotnet0824
dotnet0824 asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008
12 Comments2 Solutions354 ViewsLast Modified:
i want to build a sql dynamic statement in stored procedure

here is the following proc


create procedure bal_Customer
@customerID int,
@custType int = 0
as

declare @str varchar(100)

   if(@custType = 0)
     SET @str = 'AND SALARY' > 0   (i want salary > 0.00)
    else if(@custType = 1)
    SET @str = 'AND salary' > 0  +  'ANd revenue >' + 0


   select * from customer where  customerId = @CustomeID  +  @str  (I want to pass the dynamic string here)

  I am getting error
   Conversion failed when converting the varchar value 'AND salary >' to data type int.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros