sql-server - 在 SQL Server 中声明表变量问题
问题描述
我想声明一个表变量,并按照此页面中的步骤进行操作,但出现错误SELECT @StdRevenue;
。看来我需要声明变量 - 我做了。
表Purchasing.ProductVendor
:
我的代码
DECLARE @StdRevenue TABLE
(
ProductID int,
Revenue money
);
--insert values to columns
INSERT INTO @StdRevenue (ProductID, Revenue)
SELECT ProductID, StandardPrice * OnOrderQty
FROM Purchasing.ProductVendor
GROUP BY ProductID;
SELECT @StdRevenue;
解决方案
我希望下面的查询对您有所帮助....
Create table #temp
(
id int,
price varchar(5),
qty int
)
insert into #temp values(1,'50',1)
insert into #temp values(2,'500',4)
insert into #temp values(3,'100',6)
--Select All queries together
DECLARE @StdRevenue TABLE
(
ProductID int,
Revenue money
);
--insert values to columns
INSERT INTO @StdRevenue (ProductID, Revenue)
SELECT id, price * qty
FROM #temp
SELECT * from @StdRevenue;
----到这里
推荐阅读
- chef-infra - Chef 服务器升级问题 - 对非编码对象进行编码
- python - Python 问题 - 相关随机样本和 Cholesky 分解
- javascript - 如何有效地从 Firebase 数据库中获取数组?
- java - 如何转换收藏
- >> 列出
- > 使用 java 流
- php - 如何在 2 个 php 页面中有一个变量?
- python-3.x - 使用 numpy 将数据从 csv 加载到单个列表
- google-identity - 未显示 Web 密码凭据的一个选项卡登录
- javascript - 通过 beforeunload 捕获关闭窗口但排除 asp 按钮
- javascript - 如何使用 jquery 启用克隆 div?
- laravel - Laravel 的虚拟主机配置不重定向到公用文件夹