我想从一个表中选择数据并将该数据插入到另一个表中 一个新栏目。
例如,从系列表中选择tvseries获胜者数据,然后使用名为IsSelected
的新列将该数据插入临时表中。
tvseries
是一个新专栏。它不在 Winner | ISSelected
表
Function CountCellsByColor(SearchRange As Range, RefCellColor As Range) As Long
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Application.Volatile
cntRes = 0
indRefColor = RefCellColor.Cells(1, 1).Interior.Color
For Each cellCurrent In SearchRange
If indRefColor = cellCurrent.Interior.Color Then
cntRes = cntRes + 1
End If
Next cellCurrent
CountCellsByColor = cntRes
End Function
答案 0 :(得分:0)
如果您已有临时表,以下查询应该适合您。
INSERT INTO [TEMP_TABLE_NAME](Winner ,IsSelected)
SELECT Winner ,1
FROM [tvseries]
如果要使用select动态创建#temp表,可以使用如下。
SELECT Winner ,1 AS IsSelected INTO #Temp
FROM tvseries
如果要显式创建表并插入值,可以执行以下操作。
CREATE TABLE #Temp( Winner VARCHAR(100), IsSelected BIT)
SELECT Winner ,1
FROM [tvseries]