jdana
asked on
Bit to Boolean?
I built a simple sproc that runs an executable using xp_cmdshell. I want to be able to identify errors when the executable is called. The variable XPCmdShellResult contains a bit value. When the compiler hits the IF clause it balks, presenting the following:
An expression of non-boolean type specified in a context where a condition is expected, near 'BEGIN'.
If I modify the IF clause to the following:
IF @XPCmdShellResult > 0
The procedure runs properly, but I should be able to @XPCmdShellResult to behave as a Boolean without the comparison operator. (It's cleaner.)
An expression of non-boolean type specified in a context where a condition is expected, near 'BEGIN'.
If I modify the IF clause to the following:
IF @XPCmdShellResult > 0
The procedure runs properly, but I should be able to @XPCmdShellResult to behave as a Boolean without the comparison operator. (It's cleaner.)
CREATE PROCEDURE dbo.CallRTXMLExportTool
AS
DECLARE
@XPCmdShellCommand varchar(200),
@XPCmdShellResult bit
SET @ErrorHint = 'Not Configured'
SET @XPCmdShellCommand = 'C:\RTXMLExportTool.exe'
EXEC @XPCmdShellResult = xp_cmdshell @XPCmdShellCommand, NO_OUTPUT
IF @XPCmdShellResult -- Problematic code here.
BEGIN
-- Error code not shown.
END
GO
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CREATE PROCEDURE dbo.CallRTXMLExportTool
AS
DECLARE
@XPCmdShellCommand varchar(200),
@XPCmdShellResult bit
SET @ErrorHint = 'Not Configured'
SET @XPCmdShellCommand = 'C:\RTXMLExportTool.exe'
EXEC @XPCmdShellResult = xp_cmdshell @XPCmdShellCommand, NO_OUTPUT
CASE WHEN ISNULL(@XPCmdShellResult,0 ) = 0 --code when your variable is FALSE or NULL
ELSE ----code when your variable is TRUE
END -- Problematic code here.
BEGIN
-- Error code not shown.
END
GO
AS
DECLARE
@XPCmdShellCommand varchar(200),
@XPCmdShellResult bit
SET @ErrorHint = 'Not Configured'
SET @XPCmdShellCommand = 'C:\RTXMLExportTool.exe'
EXEC @XPCmdShellResult = xp_cmdshell @XPCmdShellCommand, NO_OUTPUT
CASE WHEN ISNULL(@XPCmdShellResult,0
ELSE ----code when your variable is TRUE
END -- Problematic code here.
BEGIN
-- Error code not shown.
END
GO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did you check my code. I used ISNULL function to resolve the problem.
Sharath_123, you can't use CASE like that. CASE is not a statement.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dportas - I appreciate the two salient points. J
CREATE PROCEDURE dbo.CallRTXMLExportTool
AS
DECLARE
@XPCmdShellCommand varchar(200),
@XPCmdShellResult bit
SET @ErrorHint = 'Not Configured'
SET @XPCmdShellCommand = 'C:\RTXMLExportTool.exe'
EXEC @XPCmdShellResult = xp_cmdshell @XPCmdShellCommand, NO_OUTPUT
CASE WHEN @XPCmdShellResult = 1 --code here
ELSE --code here
END -- Problematic code here.
BEGIN
-- Error code not shown.
END
GO