| |

VerySource

 Forgot password?
 Register
Search
Author: mgs_pexp

Stored procedure receives multiple parameter problems Master invited

[Copy link]

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-26 20:45:01
| Show all posts
Upstairs, can you get the full line of code? ? ? ? ? Stop talking about ideas! !! !! !!
Reply

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-26 21:15:02
| Show all posts
Yeah ~! !! !! !! !! What I want is code, not ideas
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-26 21:30:01
| Show all posts
just for reference

CREATE PROCEDURE Test
    @idString NVARCHAR (1000) // If its value is 1,2,3,4,6,7,8
AS
    DECLARE @sql NVARCHAR (2000)

    SET @sql = 'UPDATE Images SET [Name] = `` Test' 'WHERE ID IN (' + @idStrings + ')'

    exec @sql


@idStrings is a combination of the above from your code in the form:
    imgeid1, imageid2, imageid3

The premise ID field must be an integer (such as int, bigint)
Reply

Use magic Report

0

Threads

14

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-27 02:15:01
| Show all posts
The string @idString cannot end with ",", that is, it cannot be "1,2,3,4,6,7,8,", it should be "1,2,3,4,6,7,8"
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-27 08:45:01
| Show all posts
Let's put it this way: I combined the selected image IDs into a string in the background of the page, separated by commas, such as: "1,2,3,4,6,7,8,"
This is passed to the stored procedure. The stored procedure splits the string of IDs, and then the name field is "tested" based on these IDs.
How to write specific stored procedures
-------------------------------------------------- ---
@ s = "1,2,3,4,6,7,8"

update YourTable set name = 'Test' where charindex (',' + rtrim (id) + ',', ',' + @ s + ',')> 0
Reply

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-27 13:00:01
| Show all posts
SET @sql = 'UPDATE Images SET [Name] = `` Test' 'WHERE ID IN (' + @idStrings + ')'

Where did @idStrings come from? ? ? ? ? ? Wrong?
Reply

Use magic Report

0

Threads

14

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-27 14:00:01
| Show all posts
After string combination, Trim (',') can be used for preprocessing, and it cannot be empty "" at the same time, the judgment can be added during storage.
if (@idString <> '')
begin
    DECLARE @sql NVARCHAR (2000)

    SET @sql = 'UPDATE Images SET [Name] = `` Test' 'WHERE ID IN (' + @idStrings + ')'

    exec @sql
end
Reply

Use magic Report

1

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-27 14:45:01
| Show all posts
where id in (your string)
I usually do this. You use "," to add the id together, and then execute it in SQL.
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-28 08:45:01
| Show all posts
SET @sql = 'UPDATE Images SET [Name] = `` Test' 'WHERE ID IN (' + @idStrings + ')'

Where did @idStrings come from? ? ? ? ? ? Wrong?

==================
No, it's the parameters that your program passes to the stored procedure.
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-28 12:45:01
| Show all posts
Exec @sql changed to exec (@sql)
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