| |

VerySource

 Forgot password?
 Register
Search
View: 783|Reply: 3

The sql data type conversion problem is urgent! ~

[Copy link]

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-9 11:40:01
| Show all posts |Read mode
create proc Search_Data
@Detail varchar (255),
@Address varchar (255),
@DAMode int
as
if @ Detail = '' set @ Detail = null
if @ Address = '' set @ Address = null
if @ DAMode = '' set @ DAMode = null
select * from DADevice
where Detail like '%' + isnull (@ Detail, Detail) + '%'
and Address like '%' + isnull (@ Address, Address) + '%'
and @DAMode like '%' + isnull (@ DAMode, DAMode) + '%'

This is a stored procedure that can be generated, but the error is:
Server: Message 245, Level 16, State 1, Process Search_Data, Line 9
A syntax error occurred while converting the varchar value '%' to a column of data type int.

Then help the boss, I ca n’t turn around! ~ Thank you! ~
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 21:30:01
| Show all posts
declare @damode varchar(50)

...
and @DAMode like'%'+cast(isnull(@DAMode,DAMode) as varchar(50) )+'%'
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-8-18 21:45:01
| Show all posts
@DAMode int This defines an integer
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-8-18 22:00:02
| Show all posts
create proc Search_Data
@Detail varchar(255),
@Address varchar(255),
@DAMode varchar(255)
as
if @Detail='' set @Detail=null
if @Address='' set @Address=null
if @DAMode='' set @DAMode=null
select * from DADevice
where Detail like'%'+isnull(@Detail,Detail)+'%'
and Address like'%'+isnull(@Address,Address)+'%'
and @DAMode like'%'+isnull(@DA Mode,DAMode)+'%'
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list