SSRS - Pass MDX parameter value to SQL query - visual-studio

I have a EmployeeID parameter:
="[Employee].[Employee Id].&[12345678912345]"
I have a SQL query that calls for EmployeeID parameter like this:
Where...AND (EmployeeID = #EmployeeID)
I then go into the sql dataset's parameters list and set EmployeeID's value to:
=LEFT(RIGHT(Parameters!EmoloyeeID.Value,15),14)
This should give 12345678912345. EmployeeID column in SQL table has datatype of nvarchar(25).
Now when I use lookup to connect Cube's dataset (dataset of the tablix I am working on) with this SQL dataset,
=Lookup(Cube's EmployeeName field, SQL's EmployeeName field, SQL's EmployeeStatus, "SQLDataSet")
I get no output. I get blank. (I know for fact that there is data because when I execute SQL query in SSMS with EmployeeID declared to 12345678912345, I get right EmployeeeName (matches with Cube's EmployeeName value) and EmployeeStatus values.
What am I doing wrong? Am I doing something wrong to EmployeeID parameter's value manipulation?

Is this a typo?
=LEFT(RIGHT(Parameters!EmoloyeeID.Value,15),14)
Just want to check to ensure it's not a simple fix :-)

Related

How to create an update query with typeorm and Oracle json column?

I have an Oracle table with a JSON column that I want to update, and I am using TypeORM with javascript. I need to access the JSON column in the where clause, following is the raw sql query and what I am attempting with typeORM:
Query updates the date to current date where the key's (inside the json column) value is 123.
entityManager.query(`UPDATE TABLE_NAME T
SET DATE = CURRENT_DATE
WHERE T.JSON_COLUMN.key = '123'`)
The query with createQueryBuilder:
tableRepository.createQueryBuilder()
.update('TABLE_NAME')
.set({DATE: '2021-07-23 10:07:10'})
.where('JSON_COLUMN.key = :key', {key: '123'})
.execute();
I am not sure how to access the JSON column's key in the where clause. Ideally, I would use the dot operator in SQL to access the JSON columns key value pairs, like so:
JSON_Column_Name.key = value but I cannot find a way to implement it with Oracle.
Any help would be appreciated.

How to create a blank/empty column with SELECT query in oracle?

I want to generate an output with blank/empty column with a "Select" query in oracle. I'm able to achieve this with below sql query:
SELECT CustomerName AS Customer, "" AS Contact
FROM Customers;
So when I run above sql query it returns a table with two columns "Customer" column with content in it and "Contact" column with no content or blank column.
I want to achieve same with oracle query. Any help will be highly appreciated.
I think you should use null
SELECT CustomerName AS Customer, null AS Contact
FROM Customers;
And Remember that Oracle
treats a character value with a length of zero as null.
In DB2, using single quotes instead of your double quotes will work. So that could translate the same in Oracle..
SELECT CustomerName AS Customer, '' AS Contact
FROM Customers;
I guess you will get ORA-01741: illegal zero-length identifier if you use the following
SELECT "" AS Contact FROM Customers;
And if you use the following 2 statements, you will be getting the same null value populated in the column.
SELECT '' AS Contact FROM Customers; OR SELECT null AS Contact FROM Customers;

Column name is masked in oracle indexes

I have a table in oracle db which has a unique index composed of two columns (id and valid_from). The column valid_from is of type timestamps with time zone.
When I query the SYS.USER_IND_COLUMNS to see which columns my table is using as unique index, I can not see the name of the valid_from column but instead I see smth like SYS_NC00027$.
Is there any possibility that I can display the name valid_from rather than SYS_NC00027$. ?
Apparently Oracle creates a function based index for timestamp with time zone columns.
The definition of them can be found in the view ALL_IND_EXPRESSIONS
Something like this should get you started:
select ic.index_name,
ic.column_name,
ie.column_expression
from all_ind_columns ic
left join all_ind_expressions ie
on ie.index_owner = ic.index_owner
and ie.index_name = ic.index_name
and ie.column_position = ic.column_position
where ic.table_name = 'FOO';
Unfortunately column_expression is a (deprecated) LONG column and cannot easily be used in a coalesce() or nvl() function.
Use the below to verify the col info.
select column_name,virtual_column,hidden_column,data_default from user_tab_cols where table_name='EMP';

SQL Server 2008 search for date

I need to search rows entered on a specific date.
However the datatype of column I need to search on is datetime, and the datatype of argument is Date.
I can use the the query like
Select result
from table
where
convert(date, Mycolumn) = #selectedDate
but this would affect the SARGability of the query and will not use indexes created on mycolumn.
I was trying to use the following query:
Select result
from table
where
Mycolumn
BETWEEN #selectedDate AND Dateadd(s, -1, Dateadd(D, 1, #selectedDate))
However this does not work since the #selectedDate is Date type and a second can't be added or removed.
Can someone help me with a working query?
Thanks.
It is my understanding that using:
convert(date, Mycolumn) = #selectedDate
is SARGable. It will use the index on Mycolumn (if one exists). This can easily be confirmed by using the execution plan.
Select result
from table
where
Mycolumn >= #selectedDate
AND Mycolumn < Dateadd(D, 1, #selectedDate)
If you need to do these searches a lot, you could add a computed, persisted column that does the conversion to DATE, put an index on it and then search on that column
ALTER TABLE dbo.YourTable
ADD DateOnly AS CAST(MyColumn AS DATE) PERSISTED
Since it's persisted, it's (re-)calculated only when the MyColumn value changes, e.g. it's not a "hidden" call to a stored function. Since it's persisted, it can also be indexed and used just like any other regular column:
CREATE NONCLUSTERED INDEX IX01_YourTable_DateOnly ON dbo.YourTable(DateOnly)
and then do:
SELECT result FROM dbo.YourTable WHERE DateOnly = #SelectedDate
Since that additional info is stored in the table, you'll be using a bit more storage - so you're doing the classic "space vs. speed" trade-off; you need a bit more space, but you get more speed out of it.

LINQ - How to insert null DateTime into database column?

Using LINQ, how do I insert a null value into a SQL Server 2008 DateTime column?
The code below inserts "1/1/1900 12:00:00 AM",
But I want to insert "NULL" instead
CreatDate = System.Data.SqlTypes.SqlDateTime.Null
Ensure that the column in the DB is set to allow NULL and your entity property, "CreateDate" is defined as "DateTime? CreateDate {get;set;}". Then, simply set "CreateDate = null".
Your CreateDate property needs to be declared Nullable<DateTime> (aka DateTime?). Then, you can set that property on your Linqed-up object to null (not System.Data.SqlTypes.SqlDateTime.Null, just plain old C# null) and you should get the desired result. This of course assumes that your SQL table has the column properly defined to allow NULLs and that your definition for the column in the DBML also allows them.

Resources