Is it possible to return different table variables through SQL Server table valued function based on param value passed in it? - sql

I have written some set of statements which returns a table with some static columns. But I'll required to download csv format using the same function with different column. (Reason is that I created static columns to display high charts and we are using custom code to export chart data so require some different format to download)
In table valued function, I dont know how to return the Dynamic columns of the table based on pram passed to function.
How to write the table value function for this scenario? If this is not possible then what would be the alternative for this task(Stored procedure can't be used in my existing scnerio due to some limitation of code)?
Any suggestions please.

Related

Adding today date in Table name when using Create Table function in standard sql GBQ

I am quite new to GBQ and any help is appreciated it.
I have a query below:
#Standard SQL
create or replace table `xxx.xxx.applications`
as select * from `yyy.yyy.applications`
What I need to do is to add today's date at the end of the table name so it is something like xxx.xxx.applications_<todays date>
basically create a filename with Application but add date at the end of the name applications.
I am writing a procedure to create a table every time it runs but need to add the date for audit purposes every time I create the table (as a backup).
I searched everywhere and can't get the exact answer, is this possible in Query Editor as I need to store this as a Proc.
Thanks in advance
BigQuery doesn't support dynamic SQL at the moment which means that this kind of construction is not possible.
Currently BigQuery supports Parameterized Queries but its not possible to use parameters to dynamically change the source table's name as you can see in the provided link.
BigQuery supports query parameters to help prevent SQL injection when
queries are constructed using user input. This feature is only
available with standard SQL syntax. Query parameters can be used as
substitutes for arbitrary expressions. Parameters cannot be used as
substitutes for identifiers, column names, table names, or other parts
of the query.
If you need to build a query based on some variable's value, I suggest that you use some script in SHELL, Python or any other programming language to create the SQL statement and then execute it using the bq command.
Another approach could be using the BigQuery client library in some of the supported languages instead of the bq command.

Is it possible to specify a function in a bind variable using Oracle?

When inserting data into an Oracle table from .NET is it (and how) possible to specify a function as a bind variable instead of a value?
The example below is simplistic on purpose.
For example;
dim oraCommand as OracleCommand = new OracleCommand("insert into dummy(dummy_string) values :value_to_insert")
oraCommand.Parameters.Add("value_to_insert", OracleDbType.VarChar, 200)
oraCommand.Parameters("value_to_insert").Value = "MY_USER_DEFINED_FUNCTION(23,98,"TEST")
Where "MY_USER_DEFINED_FUNCTION" is a function that returns a string. I have values which can be used by an existing Oracle function to provide the value to be inserted in the DB. Since these values are time critical, I need to call the function as I am inserting the data rather than call Oracle get the data back to the client and then pass it back to Oracle.
EDIT:
I have an existing generic VB.NET function which builds insert statements from an object which contains column name, type & value for each column in the table. Igor's comment below cleared my cobwebs, and I think I've painted myself into a corner.

Use of multiple column name as input parameter or wild card in stored procedure

I would want to add an optional parameter to my stored procedure with default *. If the list of columns is provided [delimited by a comma] these columns should be returned back by the procedure. If the wildcard character is provided [star] *, all columns should be returned. Please let me know how to implement it.
First thing - why stored procedure not table UDF?
Anyway it would be easier to pass null instead of "*" - tsql allows default values on UDF parameters.
You would have to construct query dynamically and then use sp_executesql().
The issue is that you should validate columns list to prevent errors.

SQL Server - Passing a table to a function... how? and is it a good idea?

I have a stored procedure that query one of my tables. To that table I want it to add another column with a values that is calculated by a function.
The function is another query with sub queries that is based on user data in another table.
Now since there are a lot of rows to do calculations on, I figure that the same data is being queried over and over for each row by the function.
I thought I might query the needed data for the function in the stored procedure and keep it in a temp table, and pass that table to the function so the function actually queries the in-memory small table instead of making a query to the real table - that way making it faster, and not having too much IO on my real table.
My question is actually 2 parts:
is what I'm saying even makes sense? is it a good solution that will make it faster and more efficient? or is passing table data to a function comes with a high cost?
how do I pass a table to a function?
Thanks
EDIT:
BTW - it's a scalar function
You can use Table-Valued Parameters in a stored procedure or function on MS SQL Server 2008 and up:
http://technet.microsoft.com/en-us/library/bb510489.aspx

Is it possible to return Dynamic Columns using Table Valued Function in SQL Server 2005?

I have written some set of statements which returns a table with some columns. But we dont know exactly which column it returns.
In table valued function, I dont know how to return the Dynamic columns of the table.
How to write the table value function for this scenario? If this is not possible then what would be the alternative for this task?
Any suggestions please.
The table-valued function requires static columns (names and types). If you want dynamic columns in result-set, use procedure instead of function.