Table structure image atached
I have DataSet already created which has all the fields from the below query.
I am trying to concatenate First and Last Name in a report drop down parameter. I tried creating a calculated field in the DataSet, but dint work.
SELECT DISTINCT
a.DiseId,
n1.LastName,
n1.FirstName,
n1.MiddleName,
...............................
FROM Table1
I also tried creating a separate DataSet by creating the below query -
Select FirstName, lastName, convert(varchar(50),FirstName) + ' ' +
convert(varchar(50),lastName) as FullName from Table2
I can see the Concatenation result in a drop down but I get this below error, this error occured only after I created the new data set with concatenation query.
An error occurred during local report processing.
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
How do I go about to remove the error and create the filter??
Have you tried:
select Distinct FirstName||' '||LastName FullName from table2
Then in your first dataset, use
...where FirstName||' '||LastName = :ParameterName
or if you have multiple selections, do this
...where FirstName||' '||LastName in (:ParameterName)
Related
I am trying to execute the query as below in SQL Server but it is very slow due to the Replace function, can anyone help in optimizing the query to run very fast
SELECT
dbo.Orders.OrigID
FROM
dbo.Orders
INNER JOIN
dbo.OrderedReports ON dbo.Orders.OrigID = dbo.OrderedReports.OrderID
WHERE
(REPLACE(Orders.Email, '^^', '''') = 'Khengtjinyap#gmail.com')
One simple long term fix here would be to simply remove the ^^ symbols from the email before you insert the data. In order to deal with the email data which already exists in the Orders table, you could do the following one-time update:
UPDATE Orders
SET Email = REPLACE(Email, '^^', '')
WHERE Email LIKE '%^^%';
You could also create a new column which contains the cleaned up email addresses. Once you have made this change, just use a direct equality comparison in your query, which can now also use an index on the Email column.
I am currently attempting to combine 2 columns into 1 using CONCAT().
I have
SELECT
ApplicationTitle,
ApplicationVersion,
CONCAT(ApplicationTitle,' ',' - ',' ',ApplicationVersion) as ApplicationName
FROM
<DataBaseName>
-- Hid DataBase name due to privacy concerns.
Now this works and gives me the result I would like, but I need to not just see the result but actually insert it into the table as a new column with those values so I can delete ApplicationTitle and ApplicationVersion. Reasoning is when exporting the information (I do not have control over how the information gets exported out), it separates ApplicationTitle from ApplicationVersion (to clarify, they are application names and application versions, but I need it into 1 column with a - divider, e.g. ApplicationTitle = SQL, ApplicationVersion = 4.0, I want ApplicationName = SQL - 4.0). I've looked online but could not find something similar that worked for my current situation due to needing to delete ApplicationTitle and ApplicationVersion after ApplicationName has been populated.
What is the best way to go about doing this. My thought was INSERT INTO command with CONCAT but that doesn't seem to work for me (I'm sure I'm missing something).
Suppose You have a table named TableName and TableName has one column name ColumnName, then you can insert row at TableName by following query:
INSERT INTO TableName
(ColumnName)
SELECT
CONCAT(ApplicationTitle, ' ', ' - ', ' ', ApplicationVersion)
FROM YourTableName
This will create a new table and insert the records how you like, but if you try to run this again with the same table name it will give an error like "table already exists":
SELECT
ApplicationTitle,
ApplicationVersion,
ApplicationName = CONCAT(ApplicationTitle,' ',' - ',' ',ApplicationVersion)
INTO <NewTableName>
FROM <DataBaseName>
I have two different databases. I have tried using an UPDATE query, but it comes back with an unrecognised error .
How can I reference the DB in the SQL query.
The location is like this for both:
SERVER01\ABC.DB1
And
SERVER01.DB2
EDIT 1:
I have tried
insert into [DB1].[dbo].[table1]
select col1 from [ABC.DB2].[dbo].[table2]
But, I get this error,
Invalid object name 'ABC.DB2.dbo.table2'.
You can specify the database name in the query:
insert into [DbName1].[dbo].[Table1]
select * from [ABC.DB2].[dbo].[Table1]
OK this seems like it should be insanely easy, but I cannot figure it out. Every where I look online says to create temp tables and VB scripts and I cannot believe I have to do that. My goal is to insert all the records in a table with a date later than the max date in that destination table.
UPDATE The 2 tables are in two different non linked SQL databases
So:
Select #[User::Dated] = MAX(Dateof) from Table2
Insert into Table2
Select *
From Table1
Where DateOf > #[User::Dated]
I am trying to do this in SSIS. I declared a variable, the SQL execution step looks like it is assigning the single row output to it. But when I got go into the data flow it give me no parameters to choose, when I force the known parameter which is in the project scope it says no parameter exists
Create two OLE DB data sources each pointing at you two databases.
Create a variable called max_date and make its data type String.
Place an Execute SQL Task on the Control Flow, change its connection type to OLE DB and for the connection select the name of the data source that contains Table2. Set the ResultSet to Single Row. Add the following for the SQLStatement:
SELECT CAST(MAX(Dateof) AS VARCHAR) AS max_date FROM Table2
Go to the Result Set pane, click Add and enter the following:
Result Name: max_date
Variable Name: User::max_date
You can now use the max_date variable in an expression to create a SQL statement, for example you could use it in another Execute SQL Task which would use the second Data Connection like so:
"INSERT INTO Table2
SELECT *
FROM Table1
WHERE DateOf > '" + #[User::max_date] + "'"
Or in an OLE DB Source in a data flow like so:
"SELECT *
FROM Table1
WHERE DateOf > '" + #[User::max_date] + "'"
You can do this in a single SQL Task if you want:
Insert into Table2
Select *
From Table1
Where DateOf > (Select MAX(Dateof) from Table2)
If you want to use multiple Execute SQL Task items in the control flow, or want to make use of the parameter in a data flow instead, you have to change the General > Result Set option for your MAX() query to Single Row, then move from General to Result Set and Add a new variable for your result set to occupy.
To use that variable in your INSERT INTO.... query via Execute SQL Task, you'll construct your query with a ? for each parameter and map them in the parameter mapping section. If a variable is used multiple times in a query it's easiest to use a stored procedure, so you can simply pass the relevant parameters in SSIS.
I'm trying to execute a sql query through powerpivot and I get the following error
"Unable to convert a value to the data type requested for table (massive hex string) column (name)"
SELECT [name], [table].[group],[table2].[group2] ,SUM([number]) AS number
FROM table LEFT JOIN [table2] ON table.[group ID] = [table2].id
GROUP BY [name],[table].[group],[table2].[group2]
Powerpivot's validator is happy with the query and the same query runs fine through sql management studio, any ideas how I can fix this?
this usually happens when you are updating a query in a table that already had data from the original query, and the columns in that table already assigned datatypes based on the previous query.
Either recreate the table or change the datatypes to the ones in your new query.
Hope that helps.
I had same issue. I am querying a Powerpivot book on sharepoint and some of the values coming back were blank or "NaN xxx." This is because I made an Iferror( ,BLANK()) in the measurements.
I changed the calcualted measure from IFERROR( ,Blank()) to IFERROR( ,0) and then I could successfully query the model on sharepoint.