arrays - In TSQL Can I/How can I fill an array with data from a table?
问题描述
Here is the code I have so far. (I changed the column names and other stuff for safety)
/* declare empty array */
DECLARE @oArray varchar(26)
/* loop variables */
DECLARE @Counter INT
DECLARE @rows INT
SET @Counter = 1
SET @rows = (select count(z) from z where z like 'z-%' and z = 1)
/* fill array */
WHILE (@Counter <= @rows)
BEGIN
SET @oArray(@Counter) = (SELECT z FROM (
SELECT ROW_NUMBER() OVER (ORDER BY z ASC) AS RowNumber,*
FROM z WHERE z like 'z-%' and z = 1) AS taboo
WHERE RowNumber = @Counter)
END
It works up to the set in the while loop. Is there a way to perform something like this in TSQL? I tried to research this. However, I cannot seem to find any post like it. (for TSQL)
I need the @Counter to work at "@oArray(@Counter) = " & "WHERE RowNumber = @Counter".
I want to dynamically pull data from a particular table to be used in calculations without hardcoding in values.
解决方案
推荐阅读
- python - 如何在 pyspark 中创建数据框的副本?
- python - Python - 字符串索引超出范围问题
- html - 如何仅在 css 的帮助下在 html 中创建精美的文本
- javascript - 未找到 jsstore 变量
- swift - 如何在 IOS Swift 中添加嵌套有序字典?
- python - 如何根据 python selenium 中的列表索引超出范围来消除此错误
- archlinux - 在 Arch linux 上安装 php5.6 时检查 freetype2 错误
- javascript - vue.js中的链js函数然后方法
- amazon-web-services - KOPS:在 AWS VPC 上具有私有网络的 Kubernetes 集群:错误列出节点
- java - 当您假设在用户输入中输入某些内容但按回车键时出现异常