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

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.

Related

Azure Log Analytics: Failed to resolve table or column or scalar expression

I'm trying to build a Log Analytics Workbook using Parameters. One of the parameters is not being recognized by the workbook.
Whats going on here?
Example:
Using {STORAGE_ACCOUNT:label} as Parameter results in:
Error: " operator:Failed to resolve table or column or scalar expression named '<storageaccountname>'...
Hardcoding <storageaccountname> in the query results in no error
when using single value parameters like {STORAGE_ACCOUNT:label}, you still need to enclose them in quotes (either single or double) to make them valid strings:
let varStorageAccount = '{STORAGE_ACCOUNT:label}';
you're doing that in the example when you hardcode the string.
when using multi-value parameters (like multiselect dropdowns), then the quote and delimiter settings are part of that parameter itself. but for single value parameters like text or single select dropdown, there's no quotes by default, so that the parameters can represent things that wouldn't normally be quoted.

Use SQL Field in SSIS Variable

Is it possible to reference a SQL field in your SSIS variable?
For instance, I would like use the field from the "table" below
Select '999999' AS Physician_Profile_ID
as a dynamic variable (named "CMSPhysProID" in our example) here
I plan on concatenating multiple IDs into a In statement.
Possible by using execute sql taskIn left side pan of Execute SQL task, general tab 1.Select result set as single row2. Connection type ole db 3. Set connection and form SQL statement, As you mentioned Select '999999' AS Physician_Profile_ID 4.Go to result set in your left side pan 5. Add your variable where you want to store '999999' 6. Click ok
If you are looking to store the value within the variable to be used later, you can simply use an Execute SQL Task with a single row result set. More details in the following article:
SSIS Basics: Using the Execute SQL Task to Generate Result Sets
If you are looking to add a computed column while importing data, you must use a Derived Column Transformation within the data flow task to add a column based on another one, you can refer to the following article for more details about this component:
SSIS Derived Columns with Multiple Expressions vs Multiple Transformations
What are you trying to accomplish by concatenating the IDs into an "IN" statement? If the idea is to use the values of the IDs to limit the results, as a dynamic WHERE clause, you may have better luck just using a lookup against either a table you maintain with the desired IDs or even a static list generated in the package with a script task. (If you can use the lookup table method it will be much easier to maintain as you only have to update a table, not your source code.)
Alternatively, you may even be able to accomplish the goal with a join. Create a temp table from the profile IDs you want to keep and join to it, or, again, use it as a lookup component. Dynamically creating a where clause using IN will come in a lot slower and will be cumbersome to maintain.

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

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.

Which keyword can be used to replace "FROM" in SQL?

I am trying to bypass a waf, and which keyword can be used to replace FROM in SQL?
FROM keyword specifies from which DB object (table, view, function etc) you want to fetch data and so there is no such replacement present.
So the simple and straight answer is NO

Using Variable as expression in Derived column transformation SSIS

Essentially I a SSIS pkg with an Execute SQL statement that dynamically writes a REPLACE function based on some table values. (ie REPLACE(REPLACE(Col1,"*","",),"###","")
ExecuteSQL result is put to variable #Cleanse
In my Derived Column conversion Im trying to call #User::Cleanse as an expression in to replace the Value of the Col1 from the DataFlow.
The result appears to be pulling the result of #Cleanse and using it as a string value rather than applying it as the REPLACE function.
When Debugging the #Cleanse value appear to be putting \ in the string, which I dont think should matter as it seems to be appliying this to other values without a problem
The result is that when running out to the CSV this is putting
"REPLACE(REPLACE(Col1" in Col1
"*" in Col2
) in Col3 etc etc
How can I get the Derived column transformation to 'see' the variable as the function, not a string value?
Many thanks in advance
Set the EvaluateAsExpression property of the variable to True.
However, binding variables as parameters to an SQL query using the Variable Mappings pane of the Execute SQL task might be a better solution