| |

VerySource

 Forgot password?
 Register
Search
View: 863|Reply: 6

A stored procedure problem?

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-20 20:00:02
| Show all posts |Read mode
I am going to write a stored procedure to output N records of an arbitrary table
But it always doesn't work. In the stored procedure that needs to pass parameters, I have not succeeded yet.
create proc SkyCms
@TableName VARCHAR (200),
@RowNumber int
As
declare @TSql varchar (100)
Set @ Tsql = "Select Top" + @ RowNumber + "From" + @ TableName
Exec (@Tsql)
go
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-6-26 11:45:01
| Show all posts
--Try
create proc SkyCms
@TableName VARCHAR(200),
@RowNumber int
As
declare @TSql varchar(8000)
Set @Tsql='Select Top'+convert(varchar(8000),@RowNumber)+'* From'+ @TableName
Exec(@Tsql)
go
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-6-27 13:00:01
| Show all posts
--try

create proc SkyCms
@TableName VARCHAR(200),
@RowNumber int
As
declare @TSql varchar(8000)
Set @Tsql='Select Top'+rtrim(@RowNumber)+' * From'+@TableName
Exec(@Tsql)
go
Reply

Use magic Report

0

Threads

35

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-6-27 18:45:01
| Show all posts
RTRIM
Return a string after truncating all trailing spaces.

Learn, hehe.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-6-27 20:15:01
| Show all posts
The purpose of the above SQL is to convert the data type
Reply

Use magic Report

0

Threads

10

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-6-28 17:00:01
| Show all posts
create proc SkyCms
@TableName VARCHAR(200),
@RowNumber int
As
declare @TSql varchar(8000)
Set @Tsql='Select Top'+rtrim(@RowNumber)+' * From'+@TableName
Exec(@Tsql)
go
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-6-29 00:30:01
| Show all posts
correct. .
1. The original @RowNumber is an int type variable. When connected to the target string, it must be converted to a type such as char() and then operated;
2. The table column was originally missing. . *
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