| |

VerySource

 Forgot password?
 Register
Search
View: 1164|Reply: 8

Executing Dynamic SQL with Exec. Problem with dot (.) In string variable in dynamic SQL

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-17 01:00:01
| Show all posts |Read mode
set @ vSQL = @ vSQL + 'delete from' + @ FSrvName + 't_Item where FNumber =' '' + @ FDeNumber + '' 'and FItemClassID = 2001'

Execute (@vSQL)

The value of the string variable (@FDeNumber) in the above dynamic SQL (@vSQL) is: '03 .001 ', and an error is reported after execution.
But when there is no dot in the middle of the string variable value, such as: '03001', it can be executed normally.
Seeking solutions, 100,000 rush !!!
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-1-21 22:18:02
| Show all posts
What type is FNumber?
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-22 10:36:01
| Show all posts
Dynamic SQL has nothing to do with ".", Look for other errors.

set @ vSQL = @ vSQL + 'delete from' + @ FSrvName + 't_Item where FNumber =' '' + @ FDeNumber + '' 'and FItemClassID = 2001'
print @vSQL-use the print result to execute it.

--Execute (@vSQL)


unkmassBrother is still online. It's not easy, I'm going to rest.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-22 14:54:01
| Show all posts
Should be an error during data type conversion
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-22 16:27:01
| Show all posts
declare @str varchar (10)
set @ str = '03 .001 '
select cast (@str as int)
-Error

declare @str varchar (10)
set @ str = '03001'
select cast (@str as int)
--OK
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-24 11:09:01
| Show all posts
-----------------------------------
Select @ vSQL = ''-here the variable is assigned (it can be empty or other values)
-----------------------------------

set @ vSQL = @ vSQL + 'delete from' + @ FSrvName + 't_Item where FNumber =' '' + @ FDeNumber + '' 'and FItemClassID = 2001'

Execute (@vSQL)
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-24 11:18:02
| Show all posts
declare @str varchar (10)
set @ str = '03 .001 '
select convert (decimal (5,3), @ str)
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-24 11:45:01
| Show all posts
What's wrong?
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 Germany

Post time: 2020-1-24 14:18:01
| Show all posts
It should be for the sake of data type conversion ..
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