Using SQL Server Management Studo v 18.12.1 on a VDI with 64bit Windows Microsoft SQL Server 2019. This device has 96 GB of free space and also has free temporary space.
I loaded a new database and table which has 1,301,902 rows from a csv with no errors using the Data import tool. I have used this on several other tables in this server with no problem.
I run a query like this
set rowcount 10
select xyz.["PPI"],xyz.["Business Mailing Address One"]
from [DBNAME].[dbo].[table_name] xyz
and this returns:
"PPI" "Business Mailing Address One"
"7251" "2100 S TRAVIS DR"
"1346" "392 HAWKINS ST"
"1351" "PO BOX 81001-0798"
"0289" "123 E MAIN ST"
"4022" "2890 KLAMATH FALLS BLVD"
"19118" "3639 E FALLS DR"
"8421" "" ""
"45800" "" ""
"6507" "" ""
"1112" "" ""
Then run this query
set rowcount 0
select xyz.["PPI"],xyz.["Business Mailing Address One"]
from [DBNAME].[dbo].[table_name] xyz
where xyz.["Business Mailing Address One"] like 'PO%'
This returns:
"PPI" "Business Mailing Address One"
zero rows... Query executed successfully
Using = 'PO%' has the same result
Also copied the response into the where statement like
where xyz.["Business Mailing Address One"] = 'PO BOX 81001-0798'
and also get the same result
Taking your data exactly how it is, and assuming that all values appear in the dataset are surrounded with quotes, you would need to ensure your fuzzy search also starts with a quote.
DECLARE #Data AS TABLE(
["PPI"] VARCHAR(10),
["Business Mailing Address One"] NVARCHAR(50)
)
INSERT INTO #Data VALUES
('"7251"', '"2100 S TRAVIS DR"') ,
('"1346"', '"392 HAWKINS ST"'),
('"1351"', '"PO BOX 81001-0798"'),
('"0289"', '"123 E MAIN ST"'),
('"4022"', '"2890 KLAMATH FALLS BLVD"'),
('"19118"', '"3639 E FALLS DR"'),
('"8421"', '" "'),
('"45800"', '" "'),
('"6507"', '" "'),
('"1112"', '" "')
SELECT xyz.["PPI"], xyz.["Business Mailing Address One"]
FROM #Data xyz
WHERE xyz.["Business Mailing Address One"] like '"PO%'
Related
I am trying to alter an existing programm in VB , I am not experienced in this language , but unfortunately I cannot convert it for now.
I created the DB Connections with the Designer , which automatically created the BindingSource, TableAdapter , DataSet .
I insert something into this table like this :
Me.Validate()
myBindingSource.EndEdit()
myTableAdapter.Insert(1, 1, "test", 100, Now, 1, Now)
I would now like to get CURRENT_SEED valuer for the ID field ( which is Autoincrement )
can I do it somehow here without making some extra connection , is it returned somewhere ?
Regards
Robert
If you want to use table adapters for ease, just created a "Select Max(ID) From myTable" scalar query then just call it to get the last value.
int resultID = myTableAdapter.GetLastID();
I am currently trying to help a friend out with their invoicing Access database. I have rarely ever used Access and I am having problems figuring out the location of where the form (frmEntry) is pulling its data from. I did not create this setup so I am unsure of how it works. I am trying to figure out where the address information is being pulled from for when a customer is selected in a drop down on a form. I checked the query and it is only pulling the CustomerID and CustomerName, no address. The table does have address fields but none of the customers in the table have any listed, yet there address is populated along with their name in the form.
I do see where there is another form (frmCustomer) that has customer and there addresses but I am not sure if the other form is pulling from here, and if so, why can I not find the addresses in any of the tables or datasheet views?
Any direction would be very much appreciated. My end goal is to obtain the customer information (address etc) so that I can insert it into a new database that I am working on
Your data contains linebreaks and a combobox only shows one line per record.
To show the data you can replace the linebreaks in rowsource.
SELECT Replace([CustomerName],vbCrLf, " ") as CName FROM table
' vbCrLf is the VBA constant for linebreaks (Cr - Carrige Return, Lf - LineFeed)
This is poor database normalization (imagine you want to search for a customer name that is equal to a city, e.g. Paris). Each line should be a separate field in table (and Postcode too). If there is a linefeed for every data (e.g. no street -> empty line), you can just split the data into the new fields.
'Put this code in a module
'Split function
Public function splitCustomerName(ByVal strCustomerName as String, ByVal index as long) as String
Dim arrCustomerName As Variant ' or declare a fixed array if you know the number of lines
arrCustomerName = Split(strCustomername,vbCrLf)
splitCustomerName = arrCustomerName(index)
End Function
The query
UPDATE table SET newCustomerName = splitCustomerName([table].[CustomerName],0)
, newCustomerStreet = splitCustomerName([table].[CustomerName],1)
, newCustomerCity = splitCustomerName([table].[CustomerName],2);
Just create the necessary columns for name, street and city, then run the query.
If you delete the CostumerName column and rename the table (e.g. newTable) you can create a query with the oldname of the table, that behaves like your old table.
SELECT *
, newCustomerName & vbCrLf & newCustomerStreet & vbCrLf & newCustomerCity as CustomerName
FROM newTable
I want to generate a report in Access that depends on a parameter.
Let's say my table looks something like this:
id usr password last_seen workplace
01 test1 12345 -- M
02 test2 12345 -- G
03 test3 12345 -- M
04 test4 12345 -- H
... ... ... ... ...
(this is not my table, but for now assume it is).
Now I want to make a report where you can type in: "M" and it shows a list of people living in "M" (same for "Z", "G" and any other town).
How can I do this? I'm pretty new to Access so I really don't have an idea.
MS Access Version: 2010
Open the report query in design mode and provide a Where clause. The output is something similar to this,
Where WorkPlace = [WorkPlace]
Feel free to leave a message if you are encountering any issues.
Open the report with a filter.
In VBA:
Dim strWorkplace As String
' strWorkplace = "M"
' or interactively
strWorkplace = InputBox("Enter workplace")
' Prevent SQL injection
strWorkplace = Replace(strWorkplace, "'", "''")
DoCmd.OpenReport "YourReportName", WhereCondition:="workplace = '" & strWorkplace & "'"
For a numeric parameter, leave out the single quotes.
I have the following query:
SELECT
[tblstudentrakazot].studentid, firstname, lastname, tblRakezetSchedule.*
FROM
tblRakezetSchedule
INNER JOIN
[tblstudentrakazot] ON [tblstudentrakazot].scheduleID = tblRakezetSchedule.scheduleid
INNER JOIN
tblstudents ON [tblstudentrakazot].studentid = tblstudents.studentid
WHERE
scheduleday = datepart(w,convert(datetime,'21/2/2016',103))
AND tblRakezetSchedule.rakezetID = 182
ORDER BY
replace(scheduletimefrom, ':', '')
When run from SQL Server Management Studio, it works perfectly and generates 3 records.
When run from my VBscript app, I get no records
The issue seems to be in the filter that refers to the date scheduleday = datepart(w,convert(datetime,'21/2/2016',103)) - when I comment that out, the query works.
Does anyone know what the issue can be?
I have tried playing with the date settings but that didnt change anything.
I have tried doing CONVERT(int,scheduleday) in the WHERE - that didn't help either, as the scheduleday is already a number format field.
I have tried using dw in the datepart instead of w - also no change.
Thanks in advance
UPDATE:
The query works when I do WHERE CONVERT(int,scheduleday) = 1
Also - I see that CONVERT(int,datepart(w,convert(datetime,'21/02/2016',103))) correctly gives 1 too. Its just weird that 1 <> 1 even when they are both converted to INT
Here is my VBscript:
sql = "SELECT [tblstudentrakazot].studentid, firstname, lastname, tblRakezetSchedule.* FROM tblRakezetSchedule"
sql = sql & " INNER join [tblstudentrakazot] on [tblstudentrakazot].scheduleID = tblRakezetSchedule.scheduleid "
sql = sql & " INNER join tblstudents on [tblstudentrakazot].studentid = tblstudents.studentid"
sql = sql & " WHERE "
sql = sql & " CONVERT(int,scheduleday) = datepart(w,convert(datetime,'" & cleanSQL(planneddate) & "',103)) AND "
sql = sql & " tblRakezetSchedule.rakezetID = " & CleanSQL(x_rakezetID)
sql = sql & " ORDER BY replace(scheduletimefrom, ':', '')"
WHERE:
x_rakezetID = 182
and planneddate is a date variable in the format of `21/02/2016'
The result of SELECT datepart(w,convert(datetime,'21/2/2016',103)) will depend on your session's language settings (which will depend on the user.) For example:
SET LANGUAGE German;
SELECT datepart(w,convert(datetime,'21/2/2016',103)) ;
...returns 7, whereas for English it returns 1.
I therefore suspect that you are using different users or at least different language settings when connection through SSMS versus through your application.
I am very new to MS Access and yet have been working (loosely) on a DB for a while. We have a DB that tracks membership. There is a table with all of the member info in there. When new and current customers are added, or pay for the current year, the info is applied to a 'PaidYear' column. For years now, I have been adding a query listing the current years' members and adding a report that displays the output of the query.
I would like to create a report where I could (using a drop-down maybe) select the active year and other options such as City, Company Name, Phone Number, etc. Is there any way to simply set this up? It has to be easy enough for my replacements to intuitively use. ie:
Member Report for [Choose Year] <-- Dropdown
[City] [Company] [Phone] [Select Option]<--- Extra Options for reporting
I have been playing with it for a while and while I can get the design set up, I can't set up the functionality. Thank you so much!!!
Yup, if you want to filter down your report, you can write a little bit of VBA to open your report with a filter (you don't need to use a parameter query for this. It may be more efficient to do this at the query execution level, but as far as i've noticed, the performance is the same to just run the full query and filter it at runtime of the report open (Access might actually just do this behind the scenes, again, I don't really know.
Anyways, lets get to it. Here's a code snippet that you can kind of use as a starting point and adapt.
Create a button that says 'Run Report', let's call it cmdRunReport
In the On Click event for that button, you will put some code. I'm just writing this up now, so I might have some syntax errors (don't have Access on this PC).
dim multiple as boolean
dim filtering as string
filtering = ""
if me.yearDropdown is not null then
filtering = filtering + "[myYearField] = " & me.yearDropdown
multiple = true
end if
if me.cityDroPDown is not null then
if multiple then
filtering = filtering + "AND [myCityField] = '" & me.cityDropdown & "'"
else
filtering = filtering + " [myCityField] = '" & me.cityDropdown & "'"
set multiple = true
end if
end if
if me.CompanyDropDown is not null then
if multiple then
filtering = filtering + "AND [myCompanyField] = '" & me.CompanyDropdown & "'"
else
filtering = filtering + " [myCompanyField] = '" & me.CompanyDropdown & "'"
set multiple = true
end if
end if
DoCmd.OpenReport "yourReport", acViewPreview, , filtering
This is the basis of what you can do. I may have a couple if syntax errors and concatenated the filtering string incorrectly (untested), but that's where you could start.
In english, it just looks at your form's dropdowns that you use to filter. It checks if they are not null, and then concatenates their values into the "filtering" string. This string is used as a parameter in your OpenReport method.
Hope this helps.