Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use parameter name more than once in a script #422

Open
2 tasks done
xperiandri opened this issue Aug 28, 2022 · 3 comments
Open
2 tasks done

Cannot use parameter name more than once in a script #422

xperiandri opened this issue Aug 28, 2022 · 3 comments
Assignees

Comments

@xperiandri
Copy link

Issue Summary

When I try to use @assetId twice error is displayed

    MERGE INTO [dbo].[AssetName] AS Target
    USING (VALUES
      (@assetId, 11, @ukrainianName, 5, N'Afroz Yadwad'),
      (@assetId, 10, @russianName, 4, N'Afroz Yadwad')
    ) AS Source ([AssetId],[LanguageId],[InternalName],[OrderBy],[CreatedBy])
    ON  Target.[AssetId] = Source.[AssetId]
    AND Target.[LanguageId] = Source.[LanguageId]

    WHEN NOT MATCHED BY TARGET THEN
        INSERT ([AssetId],[LanguageId],[InternalName],[OrderBy],[CreatedBy])
        VALUES ([AssetId],[LanguageId],[InternalName],[OrderBy],[CreatedBy])

    WHEN MATCHED THEN
        UPDATE SET TARGET.[InternalName] = Source.[InternalName]
    ;

Error

Incorrect syntax near 5

Expected behavior

The parameter name is reused and can be referenced more than once

What you can do

  • I am willing to contribute a PR with a unit test showcasing the issue
  • I am willing to test the bug fix before the next release
@jackfoxy
Copy link

I used to use this provider all the time, but it has been years. It cannot be upgraded to dotnet without a lot of work.
IIRC there is a workaround, which is to define a new @variable for each time it is used. You can do it within your script. Declare and set the second variable to the original variable submitted to the script.

@smoothdeveloper
Copy link
Collaborator

@xperiandri this is described in question 4 in the faq: https://fsprojects.github.io/FSharp.Data.SqlClient/faq.html and due to how sys.sp_describe_undeclared_parameters works.

@xperiandri xperiandri changed the title Cannot use parametr name more than once in a script Cannot use parameter name more than once in a script Aug 29, 2022
@daniellittledev
Copy link

I think it also works if you declare the type in TableVarMapping
TableVarMapping = "@assetId=Int"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants