SQL Frustration

Kathleen0422

Board Regular
Joined
Apr 12, 2006
Messages
188
TheDivision = PE
TheLoadDate = 7/6/2007


This works wonderfully, but I want to add a parameter being that TheLoadDate is greater than Date_Loaded


With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=#####UID=OT_User;pwd=######;APP=Microsoft Office 2003;WSID=#####00" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT view_" & TheDivision & "_Hours.TMID, view_" & TheDivision & "_Hours.CostCenter, view_" & TheDivision & "_Hours.TRC_Code, view_" & TheDivision & "_Hours.Name, view_" & TheDivision & "_Hours.Approval_Date, view_" & TheDivision & "_Hours.Date_Worked, view_" & TheDivision & "_Hours.Hours, view_" & TheDivision & "_Hours.Project_ID, " _
, _
"view_" & TheDivision & "_Hours.Title, view_" & TheDivision & "_Hours.Work_Location, view_" & TheDivision & "_Hours.Date_Loaded" & Chr(13) & "" & Chr(10) & "FROM OTRPT.dbo.view_" & TheDivision & "_Hours view_" & TheDivision & "_Hours" & Chr(13) & "" & Chr(10) & "WHERE (view_" & TheDivision & "_Hours.Date_Loaded>{ts '2007-07-06 00:00:00'})" & Chr(13) & "" & Chr(10) & "ORDER BY view_PE_" _
, "Hours.Name")
.Name = "Query from Hours"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With


so when I modify the Statement to this:

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=#####;UID=OT_User;pwd=#####;APP=Microsoft Office 2003;WSID=##### _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT view_" & TheDivision & "_Hours.TMID, view_" & TheDivision & "_Hours.CostCenter, view_" & TheDivision & "_Hours.TRC_Code, view_" & TheDivision & "_Hours.Name, view_" & TheDivision & "_Hours.Approval_Date, view_" & TheDivision & "_Hours.Date_Worked, view_" & TheDivision & "_Hours.Hours, view_" & TheDivision & "_Hours.Project_ID, " _
, _
"view_" & TheDivision & "_Hours.Title, view_" & TheDivision & "_Hours.Work_Location, view_" & TheDivision & "_Hours.Date_Loaded" & Chr(13) & "" & Chr(10) & "FROM OTRPT.dbo.view_" & TheDivision & "_Hours view_" & TheDivision & "_Hours" & Chr(13) & "" & Chr(10) & "WHERE (view_" & TheDivision & "_Hours.Date_Loaded>{ts '" & Format(TheLoadDate, "mm/dd/yyyy") & " 00:00:00'})" & Chr(13) & "" & Chr(10) & "ORDER BY view_PE_" _
, "Hours.Name")
.Name = "Query from Hours"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With


IT BOMBS error 1004 General ODBC , I am so frustrated PLEASE HELP
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I'm not too farmiliar with ODBC, but I do see something that might be of interest.

From the code you said works:
Code:
SERVER=#####UID=OT_User;

From the modified code:
Code:
SERVER=#####;UID=OT_User;

I also noticed that it seem's that you are formatting your date differently than what was in the first string:

Date format first string: '2007-07-06 00:00:00'
Date format second string: '07/06/2007 00:00:00'

Hope I helped a little.
Chad
 
Upvote 0
Thank you it was the date, I can't tell you how many times I rewrote that always mm-dd-yyyy and it needed to be yyyy-mm-dd

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,586
Messages
6,120,402
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top