----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 10:10:02
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[CraneTrends]
if object_id('[CraneTrends]') is not null drop table [CraneTrends]
go
create table [CraneTrends]([CraneType] varchar(3),[tablename] varchar(14))
insert [CraneTrends]
select '002','Craneopration' union all
select '003','Craneopration3' union all
select '001','Craneopration1'
--------------开始查询--------------------------
DECLARE @sql NVARCHAR(MAX),@CraneType VARCHAR(10) ='002'
SELECT @sql= 'select * from '+tablename
from cranetrends
where cranetype=@CraneType
EXEC( @sql)
#10
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 10:10:02
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[CraneTrends]
if object_id('[CraneTrends]') is not null drop table [CraneTrends]
go
create table [CraneTrends]([CraneType] varchar(3),[tablename] varchar(14))
insert [CraneTrends]
select '002','Craneopration' union all
select '003','Craneopration3' union all
select '001','Craneopration1'
--------------开始查询--------------------------
DECLARE @sql NVARCHAR(MAX),@CraneType VARCHAR(10) ='002'
SELECT @sql= 'select * from '+tablename
from cranetrends
where cranetype=@CraneType
EXEC( @sql)
#11
select * from tb ,你造了啥数据呀
TableName 别都是 CraneOperation3
#12
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 10:10:02
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[CraneTrends]
if object_id('[CraneTrends]') is not null drop table [CraneTrends]
go
create table [CraneTrends]([CraneType] varchar(3),[tablename] varchar(14))
insert [CraneTrends]
select '002','Craneopration' union all
select '003','Craneopration3' union all
select '001','Craneopration1'
--------------开始查询--------------------------
DECLARE @sql NVARCHAR(MAX),@CraneType VARCHAR(10) ='002'
SELECT @sql= 'select * from '+tablename
from cranetrends
where cranetype=@CraneType
EXEC( @sql)
谢谢版主啊,不过我根据你之前给我的那个sql语句,琢磨出了个简单的方法
declare @sql nvarchar(max),@cranetype nvarchar(max)
set @sql=''
set @cranetype='001'
select @sql=@sql+'select * from ' +tablename from cranetrends where cranetype=@cranetype
select @sql
exec(@sql)
再次谢谢版主!
#13
你的方法也行...记得结贴
#14
select * from tb ,你造了啥数据呀
TableName 别都是 CraneOperation3
不会呀,传进去的CraneType不同,TableName也不同
#15
你的方法也行...记得结贴
结过啦,查收吧
#1
select 'select * from '+tablename
from cranetrends
where cranetype=你传入的参数
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 10:10:02
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[CraneTrends]
if object_id('[CraneTrends]') is not null drop table [CraneTrends]
go
create table [CraneTrends]([CraneType] varchar(3),[tablename] varchar(14))
insert [CraneTrends]
select '002','Craneopration' union all
select '003','Craneopration3' union all
select '001','Craneopration1'
--------------开始查询--------------------------
DECLARE @sql NVARCHAR(MAX),@CraneType VARCHAR(10) ='002'
SELECT @sql= 'select * from '+tablename
from cranetrends
where cranetype=@CraneType
EXEC( @sql)
#10
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 10:10:02
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[CraneTrends]
if object_id('[CraneTrends]') is not null drop table [CraneTrends]
go
create table [CraneTrends]([CraneType] varchar(3),[tablename] varchar(14))
insert [CraneTrends]
select '002','Craneopration' union all
select '003','Craneopration3' union all
select '001','Craneopration1'
--------------开始查询--------------------------
DECLARE @sql NVARCHAR(MAX),@CraneType VARCHAR(10) ='002'
SELECT @sql= 'select * from '+tablename
from cranetrends
where cranetype=@CraneType
EXEC( @sql)
#11
select * from tb ,你造了啥数据呀
TableName 别都是 CraneOperation3
#12
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-08-14 10:10:02
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据:[CraneTrends]
if object_id('[CraneTrends]') is not null drop table [CraneTrends]
go
create table [CraneTrends]([CraneType] varchar(3),[tablename] varchar(14))
insert [CraneTrends]
select '002','Craneopration' union all
select '003','Craneopration3' union all
select '001','Craneopration1'
--------------开始查询--------------------------
DECLARE @sql NVARCHAR(MAX),@CraneType VARCHAR(10) ='002'
SELECT @sql= 'select * from '+tablename
from cranetrends
where cranetype=@CraneType
EXEC( @sql)
谢谢版主啊,不过我根据你之前给我的那个sql语句,琢磨出了个简单的方法
declare @sql nvarchar(max),@cranetype nvarchar(max)
set @sql=''
set @cranetype='001'
select @sql=@sql+'select * from ' +tablename from cranetrends where cranetype=@cranetype
select @sql
exec(@sql)
再次谢谢版主!
#13
你的方法也行...记得结贴
#14
select * from tb ,你造了啥数据呀
TableName 别都是 CraneOperation3