| |

VerySource

 Forgot password?
 Register
Search
View: 902|Reply: 9

Ask SQL statements

[Copy link]

3

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-15 17:30:01
| Show all posts |Read mode
The following statement is always debugging
Always remind me that something is wrong nearby like

set @strSql = 'insert into #indextable (CompanyID, CompanyName, Address, Phone, Place)' +
'select CompanyID, CompanyName, Address, Phone, Place from Companywhere Place like%' + @ strPlace + '%'
exec (@strSql)
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-6-14 00:30:01
| Show all posts
--try

set @strSql ='insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Companywhere Place like''%'+@strPlace+'%'''
exec(@strSql)
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-6-14 10:00:01
| Show all posts
set @strSql ='insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Company where Place like''%'+@strPlace+'%'''
exec(@strSql)
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-6-14 10:15:01
| Show all posts
Less spaces!
set @strSql ='insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Company where Place like %'+@strPlace+'%'
exec(@strSql)
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-6-14 12:15:01
| Show all posts
There should be spaces between compnaywhere
Reply

Use magic Report

3

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-6-14 13:00:01
| Show all posts
Why is it so messy, edit it

set @strSql ='insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Company
               where Place like %'+@strPlace+'%'

exec(@strSql)
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 Unknown

Post time: 2020-6-14 16:45:01
| Show all posts
Because under normal circumstances, there should be ``behind the like'' to include
So here single quotes involve variable calls and string padding,
So Place like ``%'+@strPlace+'%''
Reply

Use magic Report

3

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-6-14 17:45:01
| Show all posts
Thank you ok
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 United States

Post time: 2020-6-14 22:00:01
| Show all posts
set @strSql ='insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Company where Place like''%'+@strPlace+'%'''
exec(@strSql)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-15 10:45:01
| Show all posts
To sum up, the correct statement is:
set @strSql ='insert into #indextable(CompanyID,CompanyName,Address,Phone,Place)'+
'select CompanyID, CompanyName,Address,Phone,Place from Company where Place like''%'+@strPlace+'%'''
exec(@strSql)
There are 2 mistakes: one is that there is no space before; the other is that two %s need to be quoted.
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