I have generated a query in the excel by using macros now "i want to import these queries into teradata and compile it and display the result Automatically".Can anyone help me with this?
With sufficient privileges in the database you can create a macro or macros that encapsulate the query. The macro(s) can be built to accept parameters if necessary. Once you have the macros built on Teradata you can replace the SQL in your Excel Macros with:
EXEC {Database}.{Macro}({parm1}, {parm2}, ... {parmn});
Excel VBA - Query on a Spreadsheet - Take a look at the answers on this SO question. You may find something to help you in the right direction with your VBA coding. It will need to be tweaked to connect with your Teradata environment.
store your queries into single string variable and remember to put ";" between queries. then use this guide
http://voices.yahoo.com/teradata-ms-excel-vba-2687156.html?cat=59
Related
Today I am being asked to format long SAS script with mainly Proc SQL which are not readable (do not respect simple SQL rules of readability):
imbricated SQL queries with no indentation
case is not respected
etc...
I tried automatic SaS formatter but it do not format Proc SQL. Do you have any ideas ? We have many scripts and the Team is ready to do that manually, it seems prone to error and I am not sure we'll have the same syntax at the end.
Any tips would be welcome!
I can add code snippets if needed but I think that the problem is clear and I am not the first to encounter it.
I would suggest ignoring the fact that you're in SAS for the moment, and instead focus on the SQL itself. Find a language you're comfortable with that has libraries that format code in other languages - Python for example can do this - and then:
Open the .sas file as a text file
Find "PROC SQL" text and grab from there to the "QUIT" (case insensitive)
Pass that inner text to the SQL code formatter
Grab the result and insert it back into the text file
Something along those lines is your best bet. SAS doesn't have anything built-in for this, so you're going to have to go outside here.
I have easily created a custom SQL Query to populate an Excel from an SQL database.
This was quite straightforward and easy (Data/from External sources/Microsoft SQL - and then edited the command text section of the connection properties)
But now, I would like to use a WHERE clause with a parameter from a cell.
From what I read on every tutorials and similar SO questions, I should simply have to use a question mark and Excel will understand it and allow me to define a cell.
Sources:
How to add parameters to an external data query in Excel which can't be displayed graphically?
That's what I did:
Unfortunately I got this dialog telling me that some info are missing:
You should use Microsoft Query first , and then change the Command Text later.
Refer from this: Excel: Send multiple values in "Command text"
I tried to find the answer myself but not knowing how to word the question caused problems :).
I have an excel workbook that I use to pull data from SQL Server 2005 using a stored procedure that accepts a parameter. I am using Microsoft Query in Excel. I am trying to get Excel to grab the parameter from a cell so that the users will not have to edit the connection. If I were to do this as SQL, I would replace the value with a ? and point it to a cell without issue. Since this is a SP, I get a strange response.
This works:
exec [GTI_mainframe].[proc_mf_forecast_authorizations] .07
This:
exec [GTI_mainframe].[proc_mf_forecast_authorizations] ?
Gives me the following message box:
[Microsoft][ODBC SQL Server Driver]Invalid parameter number
I control the SP and the excel workbook so can impliment what I need to. I had one person suggest a vba approach to reference the cell value directly. I could do that but my choice would be to not have to do it in macros. I would love to just be able to use the "refresh all" from the data tab in the ribbon bar. Any thoughts?
I recommend you XLReport; it allows you to connect to almost any database, create queries with parameters.
You can download the trial here.
I am working on a project were we need to develop SQL Reports based on some excel files.
I was able to create the ODBC for the Excel file and I was able to connect to it successfully using the Report Services.
My question is:
How can I used paramaters in the query ? When I try to use #CIF or #StartDate I get all kinds of errors and I don't know how to use parameters with SQL query for Excel.
Sample:
SELECT * FROM [Loans$] Where [CIF] = #CIF
Can anyone tell me how?
If you are successfully extracting information without trying to filter at the query level, as a workaround you can add the filtering at the DataSet level, something like:
This will extract data from the DataSet then apply any filter, not try to do it at the same time.
It's might not be addressing your root cause, but will hopefully get you up and running in the meantime.
Since you don't actually list the errors you're getting, it's hard to offer more specific advice.
I currently have a data source of a large table, sitting in workbook1. From workbook2, which is currently empty, I wish to set up a DSN connection to workbook1, so that I can query it from workbook 2.
In the SQL query result, I wish to display extra columns which are calculated using User-Defined VBA functions, the arguments of which will be other fields from the data source.
Example:
Workbook1 is Field1, F2, F3 and F4. I wish to query this and display all records, but additionally I wish to have F5=UDF(F3,F4).
I have been advised already that the solution to this is:
SELECT UDF(F3,F4) as F5
FROM \SourceWorkBookLocation\SourceWorkBook
IN ACCESS:
The problem I am having in access is not at the top of my list right now, relates to data types and trying to determine if a number in a string is <25. But the main problem is in MS Query:
IN EXCEL/MS QUERY:
The function is just not recognized; "undefined function"
I am not sure how to get it to see the function? My end goal here is to build a front end in excel, and have vba querying appropriately using user input variables passed to the queries. The querying will be done on a separately updated workbook.
Any ideas on how to get MS Query to see my UDF and accept what I am doing? Could it be a driver issue? There are a range of excel drivers to choose from.
Thanks
Looking at the info you have provided, you have tried to use two Excel workbooks as tables to query using Excel VBA UDF. Now I assume you are going to use these workbooks as your tables but in MS Access.
All most all databases is able to read standard SQL. See the thing is that each database is able to handle functions writting in their own space. In your case please write your UDF in Access VBA. Then try to execute to the same.
This is a common issue sometimes people do face, either tyring to access MS Access UDFs from Excel or vise versa. In a nutshell, when you're running MS Access, queries can call back into VBA. But when you're going through ODBC or ADO, the JET engine doesn't have the whole VBA model to draw on because it's simply not running.
You could try to do something like this:
Dim objExcl As Object
Set objExcl = CreateObject("Excel.Application")
objExcl.OpenCurrentDatabase "ExcelFileName/Path"
objExcl.Run ("UDFName")
objExcl.CloseCurrentDatabase
Set objExcl = Nothing
Frankly I prefer moving the UDF in to Acces..
References:
Create Access UDF
http://www.sqlexamples.info/SQL/inlineudf.htm