在SQL Server中的表中连接 [英] Concatenation in a table in sql server

查看:78
本文介绍了在SQL Server中的表中连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有类似的查询。

Hi all,

I have a query something like it.

DECLARE @execquery AS NVARCHAR(MAX)
SET @execquery =N'
declare @i varchar(50)
set @i=''139''

select * from ASYNCSEARCH_+@i'

Exec (@execquery)









这不执行当我运行此查询时。我想在表名中附加一个字符串。



我希望@i的变量像我一样被定义。我不需要在外面

请帮助





this is not executing when I am running this query. I want to attach a string in table name.

I want the variable of @i to be defined just like I have done.I don't need it outside
Please help

推荐答案

嗯,不 - 它不会......

看看你写的是什么:

SET @execquery = N'

声明@i varchar(50)

set @i ='''139''



select * from ASYNCSEARCH _'+ @ i
Well, no - it won't...
Look at what you wrote:
SET @execquery =N'
declare @i varchar(50)
set @i=''139''

select * from ASYNCSEARCH_'+@i

这是一个字符串,包含声明变量,然后尝试在它声明的字符串末尾添加变量...

您的意思是:

It's a single string, containing the declaration of the variable, then trying to tack the variable on the end of the string it's declared in...
Did you mean:

declare @i varchar(50)
set @i='139'
SET @execquery =N'select * from ASYNCSEARCH_' + @i


在里面声明@i的目的是什么?

你可以在下面试试吗,

What is the purpose to declare the @i inside ?
can you try this below,
DECLARE @execquery AS NVARCHAR(MAX) 
declare @i varchar(50)
set @i='139'
SET @execquery =N'
 
select * from ASYNCSEARCH_'+@i
 
Exec (@execquery)


这篇关于在SQL Server中的表中连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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