Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a 'bit' vs 'int' in a Stored Procedure

Status
Not open for further replies.

JeffCarlin

Programmer
Aug 16, 2001
33
0
0
US
I am trying to construct an SP that will allow me to pass a fieldname (always a boolean/bit field) as well as a value for that field. Here's what I've got:
Code:
CREATE PROCEDURE write_calendar_value_boo

/* @Parm1 not used */
@Parm2 varchar(50) ,    -- The Field Name
@Parm3 bit ,		-- The Field Value
@Parm4 varchar(11) ,   	-- The Patient's SSN
@Parm5 varchar(2) ,     -- The Treatment Num
@Parm6 datetime	        -- The Treatment Date

AS 

DECLARE @str varchar(255) 

SET @str = 'UPDATE tblDailyTreatment SET ' +  @Parm2 +  ' = ' + @Parm3
+ ' WHERE strTreatPatSSN = ' + @Parm4 
+ ' AND strTreatPatTreatNum = ' + @Parm5 
+ ' AND dteDateLogged = ' + @Parm6
+ ' AND LEFT(strAMPM,1) <> &quot;P&quot; '

EXEC (@str)
Problem is, it will not take @Parm3 as a &quot;bit&quot;. It will take it as an &quot;int&quot;, but then the SP will not execute.

Can anyone figure this out?
Thanks.
 
Try using CAST in the dynamic sql:

SET @str = 'UPDATE tblDailyTreatment SET ' + @Parm2 + ' = ' + CAST(@Parm3 AS char(1))
+ ' WHERE strTreatPatSSN = ' + @Parm4
+ ' AND strTreatPatTreatNum = ' + @Parm5
+ ' AND dteDateLogged = ' + @Parm6
+ ' AND LEFT(strAMPM,1) <> &quot;P&quot; '


--Angel
-----------------------------------
SELECT * FROM users WHERE clue > 0
0 row(s) selected
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top