I'm taking over a database and there is a process to update it, using Access as the front end connected to SSMS.Of course I'm stuck on the first part of 23, Step1A: Appends new records to dbo_tblLR2000NewStandard. It's asking for a couple of parameters, the window has tablename.fieldname and I've tried enter one value from the field but it didn't work. On top of that I'm going to need to update tens of thousands of rows.
Here is the code
INSERT INTO dbo_tblLR2000NewStandard ( CaseID, Casetype, [Casetype Txt], [Case Disp Txt] )
SELECT TxtLR2000NewStandard.[Case Id], TxtLR2000NewStandard.Casetype,
TxtLR2000NewStandard.[Casetype Txt], TxtLR2000NewStandard.[Case Disp Txt]
FROM TxtLR2000NewStandard
LEFT JOIN dbo_tblLR2000NewStandard
ON TxtLR2000NewStandard.[Case Id] = dbo_tblLR2000NewStandard.CaseID
WHERE (((dbo_tblLR2000NewStandard.CaseID) Is Null));
Any suggestions or pointing me towards something I can read would be greatly appreciated. I don't have much IT experience, 2.5 years out of school as a career changer and this is the first database project I've been given 1 year after getting a SQL cert. I'm at a small contractor and there really isn't anyone to ask for help. Am I up the creek?
Related
Okay I am getting stuck with my code.
What I am trying to do is use specific data from multiple tables, but I want to use basically the UNION ALL and INNER JOIN functions, however, this is not supported with the Visual Basic of Access and I require it to go to a table so that I can proceed to my next step.
The whole interface work from a form that has buttons to press for normal users, basically setting up a whole interface for importing the reports.
My original import followed the advise that I received from here for the tables:
strSQL = "INSERT INTO [Clicks Returns] " & _
"(SKU, [Item Description], [Jan 2016 FIN YTD TY % Returns]) " & _
"SELECT Sku, [Item Description], [Jan 2016 FIN YTD TY % Returns] FROM [Jan 2016 Clicks Returns];"
DoCmd.RunSQL strSQL
This works perfectly for appending the data to one table, however when importing the data from multiple tables into one table it follows this pattern:
Result Example
However, I require this to be the result:
Required Result
The issue is that Both SKU numbers would be similar and the Item Desc. would be the same.
And with the normal append method it just keep duplicating and I want it to follow a join type action, and I do not know how to approach this exactly with Visual Basics on Access.
Thank you for taking the time to review this and also providing assistance.
with getting the information from the second table, you require the table to be updated. (so insert into won't work for the second time you need to get data...)
I would however reconsider your data structure, to have 1 data column in the table, and have 1 column indicating which month. Then when reporting you can pivot that information...
so basically this table format:
1) SKU
2) Item Description
3) Month
4) Month YTD information.
In the case above, your insert into will much more easily work, and you won't need an update statement.
I hope this helps.
Kind regards,
I am sure this has been asked before and I have found several references to similar things. I just can't work out how to make it work for me.
I have a table (tblHistory) with data
Unit Number,Action,LoggerID,SensorID,CableID,Date,Data Location etc
I also have another table (tblUnit) with more data
Unit,Logger,Sensor,Cable
I want to create a query that scours tblHistory to find the most recent LoggerID, SensorID and CableID for each Unit.
To add to this there may need to be safeguards in the query in case the user does not place Logger, Sensor or Cable IDs so that it does not just find the most recent date and return a null value.
The final aspect of this which may or may not be simple is that I want this to overwrite the data in the tblUnit table so that when a new logger, sensor or cable is in place the unit uses this new data. I don't want these fields to be just edited because I want to keep a history of it. My knowledge of SQL and Access is pretty limited as I'm usually more familiar with excel and vb.
I have tried using these:
MSAccess: select N records from each category
sql for finding most recent record in a group
but being a beginner I'm not 100% sure how to apply them to my problem.
If anyone can help that would be great.
Example: (tblHistory)
Unit Number,Action,LoggerID,SensorID,CableID,ActionDate
1,Replace Sensor,,KTSM01S03,,15/02/2015
1,Replace Logger,KTSM01FM02,,,11/01/2014
1,Replace Cable,,,sa123124,10/01/2014
1,Replace Logger,KTSM01FM03,,,12/01/2014
2,Replace Sensor,,KTSM01S01,,13/01/2014
2,Replace Cable,,,sa123123,12/01/2014
2,Replace Cable,,,sa123124,16/02/2014
2,Replace Logger,KTSM01FM01,,,13/01/2014
tblUnit
Unit Number,Logger,SensorID,Cable
1,KTSM01FM01,KTSM01S01,sa123123
2,Logger1,Sensor1,Cable1
SELECT TOP 1 *
FROM tblHistory a
INNER JOIN
(SELECT Unit Number, Max([Date]) as MaxDate
FROM tblHistory
GROUP BY Unit Number) b
on a.[Unit Number] = b.[Unit Number]
and a.[Date] = b.MaxDate
You have to bracket the field called Date because Date() is a reserved function and Access will think you're trying to use the function instead of calling the field in your table. In the future, always try to avoid using reserved words as field names, it will save you a lot of headaches.
I'm running SQL queries in Orion Report Writer for Solarwinds Netflow Traffic Analyzer and am trying to add up data usage for specific conversations coming from the same general sources. In this case it is netflix. I've made some progress with my query.
SELECT TOP 10000 FlowCorrelation_Source_FlowCorrelation.FullHostname AS Full_Hostname_A,
SUM(NetflowConversationSummary.TotalBytes) AS SUM_of_Bytes_Transferred,
SUM(NetflowConversationSummary.TotalBytes) AS Total_Bytes
FROM
((NetflowConversationSummary LEFT OUTER JOIN FlowCorrelation FlowCorrelation_Source_FlowCorrelation ON (NetflowConversationSummary.SourceIPSort = FlowCorrelation_Source_FlowCorrelation.IPAddressSort)) LEFT OUTER JOIN FlowCorrelation FlowCorrelation_Dest_FlowCorrelation ON (NetflowConversationSummary.DestIPSort = FlowCorrelation_Dest_FlowCorrelation.IPAddressSort)) INNER JOIN Nodes ON (NetflowConversationSummary.NodeID = Nodes.NodeID)
WHERE
( DateTime BETWEEN 41539 AND 41570 )
AND
(
(FlowCorrelation_Source_FlowCorrelation.FullHostname LIKE 'ipv4_1.lagg0%')
)
GROUP BY FlowCorrelation_Source_FlowCorrelation.FullHostname, FlowCorrelation_Dest_FlowCorrelation.FullHostname, Nodes.Caption, Nodes.NodeID, FlowCorrelation_Source_FlowCorrelation.IPAddress
So I've got an output that filters everything but netflix sessions (Full_Hostname_A) and their total usage for each session (Sum_Of_Bytes_Transferred)
I want to add up Sum_Of_Bytes_Transferred to get a total usage for all netflix sessions
listed, which will output to Total_Bytes. I created the column Total_Bytes, but don't know how to output a total to it.
For some asked clarification, here is the output from the above query:
I want the Total_Bytes Column to be all added up into one number.
I have no familiarity with the reporting tool you are using.
From reading your post I'm thinking you want the the first 2 columns of data that you've got, plus at a later point in the report, a single figure being the sum of the total_bytes column you're already producing.
Your reporting tool probably has some means of totalling a column, but you may need to get the support people for the reporting tool to tell you how to do that.
Aside from this, if you can find a way of calling a separate query in a latter section of the report, or if you embed a new report inside your existing report, after the detail section, and use that to run a separate query then you should be able to get the data you want with this:
SELECT Sum(Total_Bytes) as [Total Total Bytes]
FROM ( yourExistingQuery ) x
yourExistingQuery means the query you've already got, in full (doesnt have to be put on one line), the paretheses are required, and so is the "x". (The latter provides a syntax-required name for the virtual table which your query defines).
Hope this helps.
I have used the answers from here to answer my questions before, but I cannot find the answer to this question.
I am writing a query that needs to pull in how many drops a driver makes. Fairly straight forward, however i need to add them together to give a total but when I use the SUM feature it does not return the correct information.
On the table Journey Header is a column with Number of drops, I need to add these up to give a total, which it does but i need my query to show the Driver, Vehicle, Total number of Drops and an Order Value, but I do not want each indivaidual record, I want them all grouped together, if that makes sense...
Below is the script i am using and part of the results beneath - for example I want the driver Chris Akwuba to show one line, with the total amount of drops he has done along with the order value (order value is working)
Thank you and I hope you can understand my rambling on....
select
sum(JH.NoofDrops) as [Number of Drops],
Jh.JourneyID,
JH.DriverName as [Driver],
VT.Name as [Vehicle Class],
SUM (OH.TotalSellPrice) as [Order Value]
from JourneyHeader JH with (NOLOCK)
LEFT JOIN VehicleType VT with (NOLOCK) on VT.VehicleTypeID=JH.VehicleTypeID
LEFT JOIN JourneyLine JL with (NOLOCK) on JL.JourneyID=JH.JourneyID
LEFT JOIN Orderheader OH with (NOLOCK) on OH.OrderID=JL.OrderID
where
JourneyDate between '2012-06-01 00:00:00' and '2012-07-20 00:00:00'
Group by JH.DriverName, VT.Name, Jh.NoOfDrops, JH.JourneyID
Number of Drops JourneyID Driver Vehicle Class Order Value
25 14520 Chris Akwuba Transit 2533.32
1 14521 Kevin O'Sullivan Hiab (Class2) 214.15
16 14522 Kevin O'Sullivan Hiab (Class2) 1672.29
9 14523 Chris Akwuba Transit 1136.69
16 14525 James O'Brien 7.5 tonne 633.18
9 14526 Errol Gray Transit 768.17
25 14527 John Hardy Transit 969.80
Remove Jh.NoOfDrops, JH.JourneyID from the group by and JourneyID from the select
eg
Group by JH.DriverName, VT.Name
Even if you write the correct SQL, your results will be incorrect, always. Since you added the with (NOLOCK) hint, your are asking to perform dirty reads you are getting back inconsistent data. See Previously committed rows might be missed if NOLOCK hint is used.
Now, if you're willing to ditch the 'gimme wrong results' hint, then you have a standing chance. But in order for that to happen, your requirements must not contradict themselves. When you say I want the driver Chris Akwuba to show one line you obviously cannot ask for the JourneyID column. You must make up your mind, either one row per Driver or one row per Journey. Not both. Once you settle one one of them, re-ask the question.
Let's say, for example, this is a quiz where the answers are already loaded into a database from different students. Inside of the table with various student entries containing various student's answers there is a row "masterentry" with all of the correct answers.
What I would like to do is code a button that will pull the master row on click and compare every other row against it. Starting with the first row, every time the column matches the master entry 1 point is assigned to a declared integer. When the row has completely been read the integer is stored in a "totalpoints" column. Then it moves on to the next row of answers.
I hope this makes sense the way I worded it, if there is an easier way to go about it I am open to suggestions. I don't really need any help establishing the connection to the sql database. Any help would be greatly appreciated, thanks in advance for anyone's time. I can provide more details if it would be helpful.
Just a rough guess based on vague idea of schema. You would just call this query from .NET (preferably stored in stored procedure, passing in a #QuizID) unless you really want to do it less efficiently by looping after pulling all of the data to the client...
;WITH master AS (SELECT a1 = Answer1, a2 = Answer2, ...
FROM dbo.Quiz
WHERE QuizID = #QuizID
AND Answer = 'masterentry'
)
SELECT a.StudentID,
Score = CASE WHEN a.Answer1 = master.a1 THEN 1 ELSE 0 END
+ CASE WHEN a.Answer2 = master.a2 THEN 1 ELSE 0 END
+ ...
FROM dbo.Quiz AS a
CROSS JOIN master
WHERE a.QuizID = #QuizID
AND a.Answer <> 'masterentry' -- or a.StudentID IS NOT NULL?
There may be some shortcuts here based on the data types. E.g. if the quiz is true/false there are some little tricks you can do to reduce the ... part.