http://imageshack.us/photo/my-images/837/6uvs.jpg/
I have the following tables and relationships.
When loading the NEW_CHALLAN form, I am trying to fill a Grid View with Product Details - Product Name, Stage, Pro, Katta, Packing, Rate, Quantity.
I am facing a problem (getting 0 records as result set) when using JOIN for this operation as there are no matching records(ChallanId, ProductId, OrderId) in the ChallanProductDetails table yet (when loading the form)
Any suggestions on how to solve this problem ?
If you are trying to load product details even tough there are no order/challan details then you can try something like below,
select a.productname,a.productprice,c.stage,c.pro...etc from product a
left outer join challanproductdetails b
on a.productid= b.productid
brother I am not sure what exactly your asking for is it to retrieve data from a view or two tables if you are retrieving only then why don't you create a view of two tables and just call it straight to the grid that will be easy.
Please correct me if I am wrong.
Related
So my basic goal is to create a database for a shopsystem, which is my task to do for my IT course. I tried to create a UPDATE-Query, that collects all the Sale Positions ("tblPosition.PositionAnzahl") ordered with a SELECT-Query and groups it by the products ordered, to have an overview about how often each product has been sold.
I want to do this to keep track of how many items are still left in the inventory.
The Query was supposed to update 1 field ("tblArtikel.ArtikelVerkauft") in my table "tblArtikel", in which all my articles and their information is stored.
However, i just found out that you cannot run UPDATE-Queries, that use SELECT-Query data, as i get a error, that says "Operation must use an updateable query".
This is the code i used for the query:
UPDATE tblArtikel as a JOIN
(SELECT p.PositionArtikelID, Sum(p.PositionAnzahl) AS SumOfPositionAnzahl
FROM tblPositionen as p
GROUP BY p.PositionArtikelID
) p
ON a.ArtikelID = p.PositionArtikelID
SET ArtikelVerkauft = p.SumOfPositionAnzahl;
Is there another way to keep track of all the Items left in my inventory, apart from doing what i did?
Here are screenshots of the 2 tables (the depending fields are circled red):
tblPositionen with field PositionAnzahl
tblArtikel with field ArtikelVerkauft
I have not worked with SQL before and only learned about it during 45 min, so ther emight be an easy way for this, but i would still appreciate every answer from you guys.
I'm working on my first (kinda) big personal project and I am stuck. I have 4 tables, 3 of which have foreign keys linking into tbl_model_details. All tables are listed below.
tbl_model_details
tbl_model_type
tbl_model_name
tbl_model_scale
Ideally I want to show data through my controller with HTTP Get. I can get Postman to to return data from my controller using _context.tbl_model_details.ToList();
Currently Postman is showing the id's for the other tables, but want them to show data from other columns within those tables instead of the id.
Within SQL I was able to build this query which displays the information I would like from the other tables, Is there an equivalent that I could make to run inside my controller? Or is there a way I can use this query that I have already made?
SELECT model_scale, model_name, info, picture, model_type, part_number, amount_owned, modified, limited_addition, date_purchase, price_paid, upc
from tbl_model_details
join tbl_model_type
on tbl_model_details.type_id = tbl_model_type.type_id
join tbl_model_name
on tbl_model_details.name_id = tbl_model_name.name_id
join tbl_model_scale
on tbl_model_details.scale_id = tbl_model_scale.scale_id
Any help from you guys would be great.
Thanks
You can use Entity Frameworks LINQ Include. This will allow you to include the sub-models in the same query:
_context.tbl_model_details
.Include(details => details.tbl_model_type)
.Include(details => details.tbl_model_name)
.ToList();
Without knowing your relationships, DBSet and Model setups, I can say that the statement will look exactly like the one I mentioned, but this may help you get on the right track.
This will allow you to later retrieve data from the sub-models:
#Model.tbl_model_scale.model_scale;
So I'm making a database of orders and I want to create a list of options for a dropdown box for an order form, but the list needs to be derived from a list of Services in another table, but it needs to match a preceeding Catagory Dropdown.
I'm not sure where I'm going wrong. The query is below.
SELECT ServiceTypes.ServiceType
FROM ServiceTypes
WHERE Orders.ServiceCatagory = ServiceTypes.ServiceType;
So orders is the db of Orders I want to pull the list into
ServiceTypes has the lists of of ServiceTypes I want to pull. It's composed of ServicType and ServiceCatagory. I need to limit the list of Service Types based on the Service Types in Orders.
So if someone selects the ServiceCatagory in orders to be "InstalL", the only results from ServiceTypes I want are those that have a ServiceCatagory that equals the Orders Service Catagory.
I suspect I need to join but I'm not sure how or what kind.
-update-
I should point out, I'm doing this in Access and just trying to populate a listbox.
My new query looks like this
SELECT ServiceTypes.ServiceType
FROM ServiceTypes
INNER JOIN Orders ON Orders.ServiceCatagory = ServiceTypes.ServiceCatagory;
Still not sure if that's right
So I've tested some of the SQL i've been using to get the information and I think I've actually got the correct code
SELECT ServiceTypes.ServiceType
FROM ServiceTypes
WHERE ServiceTypes.ServiceCatagory = Orders.ServiceCatagory
The real problem was my implementation in Access and where the query was being called.
I didn't need to use a JOIN, I just need to change where the call is being made. I.e. after the Catagory has been selected and not at the Database design level.
I have two datatables that comes from different database servers, the first looks like this:
structure from first dataTable
it shows how many clients each salesperson visited in the specified date.
The second dataTable looks like this:
structure of second dataTable
it shows how many customer the saleperson was supposed to visit.
As i said this data comes from two different servers, i need to do something like a join in database with the key fields (SLPRSNID AND DAYOFWEEK) in order to show in a report the compliance percentage of each salesperson.
My report application is made in VB.NET for desktop environment.
Thanks in advance
btw sorry for my bad english
You can use linq to datasets to accomplish what you are looking for, if that is to get the two datatables into one flattened result set. See this for a description and example: Cross Table Query of Datatables
If you want to maintain a relationship for some reason, consider designing a dataset with the two datatables and a data relation to join them. That will create functions to GetChildRows from the parent, and GetParentRow from the children.
Update #1 - Try this to convert your query result into a datatable. Creating a DataTable From a Query
Dim boundTable As DataTable = query.CopyToDataTable()
Found out Merge(DataTable) Method from MSDN. Hope it will solve your problem
Merge()
Also #SSS suggested answer can be accepted for your problem
Been rattling my brain for a while and I could not get pass how to do the SQL query that will show the relationship/connections between my two tables.
I'm working on an IT equipment inventory program. I have two tables;
SELECT serial_number, model, ship_dat, status FROM items_list
SELECT item_serial, connected-to_serial FROM connections
All items like desktops, laptops, monitors, etc are on the items_list table. To track down the relationship/connections of the items, I created the connections table. IE, Monitor with serial_number=Screen#1 is connected to a Desktop with serial_number=Serial#1. It works ok with my Window Form application because I
used a datagridview control to list all devices simple SQL query.
However, when trying to show the relationship/connection on SQL Reports I've ran out of ideas how to do it. I'm aiming to get the report look like below or something along the lines. I just need to show the connections between the items.
Thank you
You should be able to do this with a table in SSRS if that is what you are using. The query you would need to drive the table of all related items would be:
SELECT item_serial, connected-to_serial, mainItem.*, connectedItem.*
FROM connections
INNER JOIN items_list mainItem ON connections.item_serial = items_list.serial_number
INNER JOIN items_list connectedItem ON connections.connected-to_serial = connectedItem.serial_number
You can of course tailor the SELECT statement to your needs, mainItem.* and connectedItem.* will not give you the most descriptive column names. Using column aliases (found under column_alias here) you can give a more descriptive name to each column.
From here you should be able to use a table and create a row group on the main item (either name or serial number) to get the type of look you are looking to achieve here. I believe the Report Wizard actually has most of the functionality you are looking for and should handle the bulk of this. You may have to move some of the cells around to get the look you are going for though.