I am curious if it is possible to limit the results of an sql select statement by joining another table with selectable options. ie. Have one table that a user can use to update their preferences such as display a,c,d and do not display b and e. (assuming the table would only have columns a-e) (this has is separate from the question). Once the user has updated / selected their options im curious if i can create an sql select statement that would fetch the results of another table based off of the options selected by the user in the first table. I know can can create a larger statement that would include all of the results and omit them if the value is not provided. im curious if there is a way to only select particular columns based off of another table
im curious if there is a way to only select particular columns based
off of another table
No. Queries cannot have varying columns. Technically, you can make a stored procedure do something like that; but it is considered a rather poor practice.
...and doing it the right way is likely not going to be a "larger statement".
Related
SSRS matrix table is a great way to generate dynamic fields as long as values exist.
However, is there a way to "always" show these dynamic fields even if a value doesn't exist for them? The report field locations varies based on data availability and users have to add missing columns in Excel manually.
Dynamic fields go from 3 to up to 30 (at least for now based on run by values). Adding these values manually would make the report hard to maintain.
The way I have handled for this is in the SQL. I build a table of all the values I will always want, I cross join that table to my final output table and update/insert values where they need to exist. That way I guarantee the rows, and eventually columns in the matrix, exists even if they end up being null.
Does that make sense?
Jesse's solution is a good one, but if for whatever reason you can't or prefer not to change the SQL you can do it in SSRS by forcing a blank value in the cell with a expression like this:
=iif(IsNothing(Fields!.xxx.Value)," ",Fields!.xxx.Value)
Ok here is my dilemma and I am sure more experienced Access users have an easy solution. I have been manually running a set of queries to pull data for business users, that I want to create a form for so they can just run it themselves. This would be easy if it was one query, but the way I have to pull the correct data is first have to run one query that creates a table. I then use that 'new' table in a secondary query to get the data I need.
That first make table query needs to take inputs like supplier number and date range. I then use that output table in another query that sums up total dollar value of purchase orders. I can not include these two steps in one query as it creates an ambiguous outer join.
Any ideas on how I would go about creating a form for something like this?
Well after re-thinking this I think I was OVER thinking it. Instead of creating a table in the first step, I can just save it as a query and join that query to the second query. Then make a form off the two queries.
Is there a way to select rows in table in SSRS? What I mean is, when a table is populated with rows of data, I would like to select the rows of a table and perform some action on them. Like in a grid view control, the user can select specific set of rows. Can we insert a checkbox control in SSRS table that can be used to select rows of a table and perform action on selected rows?
The functionality you are looking for is not available from SSRS out of the box. There are some hacks that you can use but they seem to be a lot more work than it's worth.
The basic idea is that a query in SSRS can include an Update or Insert command. Then you use parameters to track whether or not to run the update part and to capture your Primary Key or other field for your update. You would need to use the Action to act as the on-click event and it would only work for one row at a time.
http://www.sqlservercentral.com/Forums/Topic1472163-391-1.aspx
https://dba.stackexchange.com/questions/24009/
I have joined 5 tables and done transformation on these tables. Now I got a single table at the end. Now I want to perform sql query on this single table to filter records. But I don't know how to perform simple sql query on this table. I have attached a snap shot which shows the resulting table. How I get this resulting data set as the source? I want to populate my destination after filter out this data.
I am using SSIS 2008.
Click here to see the Table on which I want to perform a simple sql query
SELECT * FROM `first_table`
where `some_column` =
(
SELECT `*`
FROM second_table
WHERE
`some_column2`='something'
LIMIT 1
)
Try this code This will help. You can even use this to connect all those four tables with each other.
From the image you posted, it looks like you have a set of data in the dataflow you're trying to query against. You need to do one of two things at this point. Either you insert the data into a table in the database and use another data flow to query it, or you use use a conditional split (or multicast and conditional splits) to filter the rows down further from there.
Without more detail about what you're actually trying to accomplish, these are the recommendations I can determine.
You could send the rows into a record set destination, but you aren't able to query it like a regular table and you'd need some C#/VB skills to access it to do more than a FOR EACH loop.
Assuming your sql query that you want to run against the resulting table is simple, you can use a script component task. By simple, I mean, if it is of this nature:
SELECT * FROM T WHERE a = 'zz' and b = 'XX' etc.
However, if your query has self joins, then you would be better of dumping the outcome of joining those 5 tables in to a physical table, and go from there.
It appears that query is going to be real straight-forward; in that case using a script component would be helpful.
A separate question: It's advisable to do the sorting at the database level. You are using 5 sort tasks in your solution. Can you please elucidate the reason?
I have tried to make this question concise in the title.
There are many answers to similar questions, but all involve naming every column in the table in the query.
What I want is a query to show me duplicate rows, but to ignore one or two columns, and I would like to be able to do it like shown in this post Return duplicate records, but without having to explicitly name every column in the table.
Is it possible?
Note: Being that this is the top google result for 'workbench how to duplicate a row' I feel inclined to provide an answer for that question. If a moderator feels this is inappropriate; feel free to help resolve the inappropriation.
Select all columns (or your target columns) from a single table, without joins or anything else that restricts in-editor inserts.
Eg: SELECT * FROM mytable ORDER BY id DESC
right-click on the row you want to copy, Copy Row
Go to the bottom of the select results, end, there should be a line with all null's
right-click on the null'ed row, Paste Row
Don't forget to nullify, or set to be the default, any columns you want to keep; like the primary index/id, or any unique constrained columns!
To insert your duplicated row use the Apply button on the lower right.
Workbench will open a dialog and show your the generated insert statements and offer to execute them for you. Permitting there are no errors you have just duplicated a row!
Run your select statement again to see your results.
I don't think there is another way. I would right-click on the table in MySQL Workbench, select "Send to SQL Editor" and "Select All Statement" as a starting point.