I've got a query that I ran against a table of stock items to change a field from false to true so that a label would be printed out as per the below.
UPDATE [StockDB].[dbo].[StockItem]
SET [UseDescriptionOnDocs] = 0
Where [UseDescriptionOnDocs] = 1
I have since been told that all of the items do not need this and to only do it for the ones in a list of 1150. From that I need to modify the query, something which I am really struggling with!, so it can only do it per item which are in the format of R368/WASHER/M4/ZINC/PL etc. I thought I may be able to do it using LIKE but it will only do one line? If I could get it to query a list from Excel or CSV that would be great.
Any pointers would be good as I'm an absolute novice with this once you get past the simple stuff like the above!
Thank you.
With MySQL (and others) you can load data from a file to a table. See http://dev.mysql.com/doc/refman/5.1/en/load-data.html to understand and for exemple.
Once you have your items loaded into a SQL table, you just have to do an update + join query. See http://dev.mysql.com/doc/refman/5.1/en/update.html to understand and How can I do an UPDATE statement with JOIN in SQL? for exemples.
Related
I have a document list that is updated periodically. The list may have up to 5 associated doc numbers associated with it. I need to generate a report that will have the primary document listed and the other 'sub documents' listed as well.
I basically need a table as show in the picture. I attempted a UNION, but if the data is dynamic, I would also continually need to update the query.
Any help or direction with this concept would be greatly appreciated.
I do not see other solution but read the recordset row by row and insert the data into new table. PIVOT would not work in this case.
I have a problem and I will explain the situation to understand more my needs:
I have all my data in one table, and I have put it into #All_Data variable. See attached image to see how it looks like
I want to return data showed in #Final_Data table
To do that I have done:
I have created an #All_Lots temp table that contains all lots
And I want to loop on this variable to find how many commands in each lot and put it into the #Final_Data temp table with corresponding Lot
I also want to get the min date and put it for the 3rd column
I have tried this query but it’s not working:
Select
#ALL_Data.Lots,
count(Select #All_Data.Commands
From #ALL_Data
Where #ALL_Data.Lots = #ALL_Lots.Lots)
From
#ALL_Data
But this is not working can you help me please thanks a lot
I am trying to write a query that will select the records from multiple tables whose field pass or fail = fail. Normally I wouldn't have a problem writing this its pretty straight forward. My problem is that I normalized the data of the fields. The field I am trying to select is called PassOrFail, however since it occurs in multiple tables I normalized the field and changed it to "Tablename"PassOrFail i.e OvenPassOrFail. My question is how do I select this field for all the tables that have this field? How would I type the WHERE and FROM expressions. Would I look something like this?
SELECT*
FROM Oven, FirstPunch
WHERE Oven.OvenPassOrFail,FirstPunch.FirstPPassOrFail = "Fail";
Or would I have to undo the normalization of the fields to get it to work? Any tips or suggestions to point me in the right direction would be appreciated.
I think I figured it out, All I had to do was add an AND statement and it worked.
SELECT *
FROM Oven, FirstPunch
WHERE OvenPassOrFail = "Fail" AND FirstPPassOrFail = "Fail";
I'm still relatively new to SQL and Pentaho.
I've pulled a table with two different IDs and need to run a query for each specific instance.
For example,
SELECT *
FROM Table
WHERE RecordA = 'value in column A'
AND RecordB = 'value in column B'
I need the results back, either appended to new columns in the original table or part of their own text file output.
I was initially looking at using a formula for this inside of Pentaho, but couldn't quite figure it out. Since I have the query written I threw it into Excel and got the concatenated results (so a string of 350 or so queries that I need to run). I'm just not sure how to accomplish this - I tried the Execute SQL Script inside of Pentaho but it doesn't seem to do output?
Any direction would be useful. I've searched a little but have come up short so far, possibly because I am still pretty new to this platform.
You can accomplish this behavior in a lot of ways, with a "Database Lookup" step for example, but I usually do that in a quite easy way and here is a example for your tests, I hope it helps.
The idea here is to have two Table input steps, the first one will fetch the IDs we want to look at. For example you may use a SQL query similar to note on the left. The result will be a 1 column stream of rows.
Next we have a Table Input that reads the rows received and executes it's query for each row. I'll add a screenshot with the options that I selected.
What it does is replace a placeholder '?' with the data that is received. If you need two columns use two '?' but remember that it will replace the first one with the first column and the second one with the second column
And you are good to go. Test it a couple of times and good luck.
And the config for the second table input.
I am looking to copy SQL long binary data from the "photo" column to the "id_photo_c" column. Both columns are in separate tables. A got a query to show exactly what I need, but unfortunately you cannot copy & paste outputs from the "Results Pane" of mssql.
I cannot copy the entire table from one to another, the new database has more rows (including some duplicates).
http://i.imgur.com/tmRpMh2.png
Here is the code:
SELECT
[GroupTables].[dbo].[VisitorsAdvanced].[RecordNumber], [
GroupTables].[dbo].[VisitorsAdvanced].[photo],
[SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c],
[SugarCRM].[dbo].[contacts_cstm].[id_photo_c]
FROM
[GroupTables].[dbo].[VisitorsAdvanced], SugarCRM].[dbo].[contacts_cstm]
WHERE
[GroupTables].[dbo].[VisitorsAdvanced].[RecordNumber] = [SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c];
It seems like such a simple task (would take two clicks in Excel) - but I can't seem to get it to work.
This isn't a duplicate question. I've seen similar questions on here, none of which describe how to simply copy data from one column to another.
Thank you.
Unless I'm missing something here, it seems like a simple update statement is all you need:
UPDATE [SugarCRM].[dbo].[contacts_cstm]
SET [id_photo_c] = [SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c]
FROM
[GroupTables].[dbo].[VisitorsAdvanced]
INNER JOIN [SugarCRM].[dbo].[contacts_cstm]
ON
[GroupTables].[dbo].[VisitorsAdvanced].[RecordNumber] = [SugarCRM].[dbo].[contacts_cstm].[xxx_id_number_c];
Isn't this as straight-forward as updating the data in the contacts_cstm table?
UPDATE contacts_cstm
SET id_photo_c = photo
FROM VisitorsAdvanced
WHERE RecordNumber = xxx_id_number_c