0

I want to execute query from WinCC SCADA via VBA script. It's simple query, when I execute it on the MS Management Studio - it works well but when i create it in VBA script - it doesn't.

sZapytanie = sZapytanie & " WHERE Data >= '"
sZapytanie = sZapytanie & datastart & "'"

The resulting query is

SELECT * FROM ArchiwizacjaDanych WHERE Data >= '2017-12-16'

This query without "WHERE" statements works well. What is wrong?

The output query from MsgBox is in the picture.

query from MsgBox

René Vogt
  • 43,056
  • 14
  • 77
  • 99
karl
  • 1
  • try datastart="20171216", maybe date format difference – Horaciux Dec 17 '17 at 18:02
  • No, I was not. Message box just pops up on the screen and i can't copy it. I'm quite new to this envoirement and debugging, sorry. – karl Dec 17 '17 at 18:04
  • let me copy/transcript it for you – René Vogt Dec 17 '17 at 18:09
  • @Horaciux yes, it works now. Do you know any easy way to format data from '2017-12-16' to '20171216'? Any VBA function? – karl Dec 17 '17 at 18:09
  • If you had a `Date` variable, you would just format it as `Format(datastart, "yyyymmdd")`, but I assume `datastart` is actually a `String` variable, so you probably want to use `Mid(datastart, 1, 4) & Mid(datastart, 6, 2) & Mid(datastart, 9, 2)`. – YowE3K Dec 17 '17 at 20:12
  • Try wrapping `#` around the date – Ryan Wildry Dec 18 '17 at 11:30

1 Answers1

0

on the phone right now

Replace ( string1, find, replacement, [start, [count, [compare]]] )

make sure you replace "-" with "" or with "0" if day or month <10

Horaciux
  • 6,322
  • 2
  • 22
  • 41