如何传递参数的变量而不是值? [英] how to pass the variable for the parameter instead of values?

查看:60
本文介绍了如何传递参数的变量而不是值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@ command = N'

使用'+ @DBName + N'



这是传递变量名称的正确方法参数?

@command=N'
use ' + @DBName + N'

this is the right way to pass the variable name for parameter?

推荐答案

你不能这样做。您无法根据变量更改正在使用的数据库。如果您正在进行选择或插入,那么是的,您将使用该方式的变量。但是,您不会使用引号或+符号。我假设您在SQL中执行此操作,而不是在代码中执行此操作。



为什么要根据参数设置您正在使用的数据库?听起来像是一个破碎的设计
You can't do that. You can't change the DB you're using, based on a variable. IF you were doing a select, or an insert, then yes, you'd use the variable that way. However, you would not use quotes, or a + sign. I assume you're doing this in SQL, not in code.

Why would you set the DB you're using, based on a parameter ? Sounds like a broken design to me


这篇关于如何传递参数的变量而不是值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆