本文介绍了从SQL中将参数传递到MS SQL中的临时变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经使用Microsoft查询创建了一个参数查询,如此处。但是当我想将参数传递给临时变量并创建表变量并编辑它们以获得所需的结果,而不是进行10到15个连接,并提到where子句中的参数,我得到错误I have created a parameter query using Microsoft query as mentioned here. But when I want to pass parameters to temporary variables and create table variables and edit them to get the desired result instead of doing 10 to 15 Joins and mentioning the parameters in the where clause I get errors和and我的代码看起来像这样,它与许多临时表和临时变量非常复杂My code looks something like this it is way complex with many temp tables and temp variablesBEGIN SET NOCOUNT ON DECLARE @sDate DATETIME, @eDate DATETIME; --used in many places to manipulate temp table SET @sdate = ? SET @edate = ? DECLARE @Temptable TABLE (Variable1 INT ,...... VariableN DECIMAL(18,4)); Manipulate @temptable Select * from @TemptableEND如何在Excel 2007中为SQL Server 2005中的数据库传递参数到temp变量?我没有权限在数据库中创建存储过程,并将它们作为参数传递给它。How is it possible to pass parameters to temp variables in Excel 2007 for a database in SQL Server 2005? I have no permission to create stored procedures in the database and pass them as parameters to it. 更新我已经通过VBA href =https://stackoverflow.com/questions/15848015/pass-parameters-to-temp-variables-in-ms-query-on-sql-server-from-excel#comment22552445_15848015> David Vandenbos 。如果没有VBA的帮助,我仍然很想知道这是否可以完成。I have figured a way through VBA as suggested by David Vandenbos. I am still curious to know if this can be done without the help of VBA.推荐答案您可以在声明前添加SET NOCOUNT变量。我在Excel 2010中与Microsoft Query和SQL Server 2005完美一致。You can add SET NOCOUNT ON before declaring the variables. I works perfectly in Excel 2010 with Microsoft Query and SQL Server 2005.SET NOCOUNT ONDECLARE @VAR1 VARCHAR(4)SET @VAR1 = '1234'SELECT @VAR1 https://social.msdn.microsoft.com/Forums/office/en-US/d8003854-d11a-44f7-960c-a042347736d7/microsoft- query-can not-run-sql-code-with-a-tsql-variables-in-it?forum = exceldev 这篇关于从SQL中将参数传递到MS SQL中的临时变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 01:48