人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

訳あって、エクセルでSQLを動かしたいです。
SQLでは
SELECT xxxxx,data,MIN(time) As times
From xxxxx
WHERE ●●●="●●●"
GROUP BY xxxxx,data;


●質問者: 匿名質問者
●カテゴリ:ウェブ制作
○ 状態 :キャンセル
└ 回答数 : 0/0件

▽最新の回答へ

質問者から

実際に今書いているVBAが途中なのですが、

Sub createInsertSql()
Dim newbook As Workbook
Dim currentCell As Range

Dim srcSheet As Worksheet
Set srcSheet = ActiveSheet

Dim targetRange As Range
Set targetRange = srcSheet.UsedRange


Dim head As String
head = "SERECT " & srcSheet.Name & " ("

Dim first As Boolean
first = True

Dim currentColumnIndex As Integer
For currentColumnIndex = 1 To targetRange.Columns.Count
If (first) Then
first = False
Else
head = head & "xxxxx,data,MIN(time)"
End If
Set currentCell = srcSheet.Cells(1, currentColumnIndex)
head = head & currentCell.Value
Next
head = head & ") "

Set newbook = Workbooks.Add

Dim currentRowIndex As Integer
For currentRowIndex = 2 To targetRange.Rows.Count

Dim sql As String
sql = head & "values ("
first = True

For currentColumnIndex = 1 To targetRange.Columns.Count
If (first) Then
first = False
Else
sql = sql & ","
End If
Set currentCell = srcSheet.Cells(currentRowIndex, currentColumnIndex)
If IsNull(currentCell) Or Trim(currentCell.Value) = "" Then
sql = sql & "null"
ElseIf IsNumeric(currentCell.Value) Then
sql = sql & currentCell.Value
Else
sql = sql & "'" & currentCell.Value & "'"
End If
Next

sql = sql & ");"

newbook.ActiveSheet.Cells(currentRowIndex - 1, 1).Value = sql
Next
End Sub


関連質問

●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ