access sql text not available for listbox - sql

I have a SQL server-backed Access database, and I'm struggling with one of my tables, "Notes".
My database has a Profile form for each user, and on their profile, I want to display notes from the Notes table. My notes table is set up like this:
NoteID (PK) int
GoerID int
NoteType int
Note (????)
StaffID int
Timestamp datetime
My issue is with the Note format. I can get a query to pull all information, but when I try to use a listbox to display the query info, the Note field is NOT available to add to the listbox.
I'm sure it's likely this is due to the field type, but I've tried every type I can think of. ntext, text, nchar, etc. Basically, I need this note field to have around 200 characters of variable text and be displayed in the listbox.
Any help would be appreciated!
Thanks
Updated with screenshot of table and datatype settings in Manager Studio:
Screencap
Also note that I've rebuilt the table several times (when changing datatypes), and in the screencap, the NOTE field is actually named [NoteText]

Use varchar(255) or (if you need Unicode) nvarchar(255).
That will translate into Text(255) (resp. Short Text in newer Access versions) on the Access side, and will work with your listbox as well.

Related

Crystal reports linking issue

I have 2 columns, they are both patient numbers. One is defined as a string
and the other is defined as Float, null. So the link is not working. What must I do to the one defined as number? It comes from an excel. I have changed the cells there to text, it's showing this change when I upload to SQL Server, but Crystal reports sees it as a number and it won't link on the string column.
I thought to add a column to the table then copy in the contents, is that the way to go?
ALTER TABLE [Programmer].[dbo].['Preventive Care-Colon Cancer Sc']
ADD PatNum datatype nvarchar(50)

How to Add Long Text Column to Access Table Via Query

I am updating a table in a .mdb format Access database with Access 2013. I want to add a new field, lets say a Description field, to an existing table.
I can add a text column using the following query
ALTER TABLE TestTable ADD Description TEXT(255);
Alternatively I could use
ALTER TABLE TestTable ADD Description varchar(255);
This works fine, and adds a column to TestTable called Description that is limited to 255 characters. If I open the table in Design View, I can see that the type of Description is listed as "Short Text". However, there is an option there to have the field be of type "Long Text" which as far as I can tell doesn't have a character limit. It is easy to manually change the type from the Design View, but I want to know if I can do this via a query.
I tried increasing the character count in my original query like so
ALTER TABLE TestTable ADD Description TEXT(300);
But then I recieve the error "Size of field 'Description' is too long."
What I want to know is can I add the column via a query such that it has a character limit greater than 255? This query is run as part of a macro that is run automatically, so I don't want to have to change it manually. My attempts at searching for a solution via Google have so far come up empty.
Found the answer shortly after posting the question. Using the query
ALTER TABLE TestTable ADD Description LONGTEXT;
creates a new column of type "Long Text". It should be noted that a character count was not necessary for this type.

Access 2010 Database Clenup

I have problems with my records within my database, so I have a template with about 260,000 records and for each record they have 3 identification columns to determine what time period the record is from and location: one for year, one for month, and one for region. Then the information for identifying the specific item is TagName, and Description. The Problem I am having is when someone entered data into this database they entered different description for the same device, I know this because the tag name is the same. Can I write code that will go through the data base find the items with the same tag name and use one of the descriptions to replace the ones that are different to have a more uniform database. Also some devices do not have tag names so we would want to avoid the "" Case.
Also moving forward into the future I have added more columns to the database to allow for more information to be retrieved, is there a way that I can back fill the data to older records once I know that they have the same tag name and Description once the database is cleaned up? Thanks in advance for the information it is much appreciated.
I assume that this will have to be done with VBA of some sort to modify records by looking for the first record with that description and using a variable to assign that description to all the other items with the same tag name? I just am not sure of the correct VBA syntax to go about this. I assume a similar method would be used for the backfilling process?
Your question is rather broad and multifaceted, so I'll answer key parts in steps:
The Problem I am having is when someone entered data into this
database they entered different description for the same device, I
know this because the tag name is the same.
While you could fix up those inconsistencies easily enough with a bit of SQL code, it would be better to avoid those inconsistencies being possible in the first place:
Create a new table, let's call it 'Tags', with TagName and TagDescription fields, and with TagName set as the primary key. Ensure both fields have their Required setting to True and Allow Zero Length to False.
Populate this new table with all possible tags - you can do this with a one-off 'append query' in Access jargon (INSERT INTO statement in SQL).
Delete the tag description column from the main table.
Go into the Relationships view and add a one-to-many relation between the two tables, linking the TagName field in the main table to the TagName field in the Tags table.
As required, create a query that aggregates data from the two tables.
Also some devices do not have tag names so we would want to avoid the
"" Case.
In Access, the concept of an empty string ("") is different from the concept of a true blank or 'null'. As such, it would be a good idea to replace all empty strings (if there are any) with nulls -
UPDATE MyTable SET TagName = Null WHERE TagName = '';
You can then set the TagName field's Allow Zero Length property to False in the table designer.
Also moving forward into the future I have added more columns to the
database to allow for more information to be retrieved
Think less in terms of more columns than more tables.
I assume that this will have to be done with VBA of some sort to modify records
Either VBA, SQL, or the Access query designers (which create SQL code behind the scenes). In terms of being able to crunch through data the quickest, SQL is best, though pure VBA (and in particular, using the DAO object library) can be easier to understand and follow.

SSRS report not displaying data

I have just created an SQL Server 2005 SSRS report and the data is not being displayed in the Preview pane.
The dataset is correctly populated from a stored procedure against a String parameter. I can execute it in the Data pane. When running the report in the Preview pane the correct number of rows are displayed but the contents of the cells do not contain any data
The source dataset is based on a Stored Procedure with a passed in String parameter in SQL Server 2005 that return the contents of a temp table. The dataset then maps the fields to locals. I can execute this correctly in teh Data view.
Stored Procedure
ALTER PROCEDURE spWebReportStage25BuildReview
#BuildNumber as nvarchar(50)
Temp table schema
CREATE TABLE #tmpModelZones
(
BuildID bigint NOT NULL,
BuildNo nvarchar(50) NOT NULL,
ModelID int NOT NULL,
ModelName nvarchar(50) NOT NULL,
ZoneID int NOT NULL,
ZoneName nvarchar(50) NOT NULL,
SortOrder int NOT NULL,
Created bit DEFAULT 0 NOT NULL,
Closed bit DEFAULT 0 NOT NULL,
PRIMARY KEY (BuildID, ZoneID)
)
SSRS Dataset
SSRS Dataset mapping
SSRS Dataset Parameter
Executing Dataset with parameter
There are no additional grouping, filters or aggregation on the displayed table. It is simply a flat table
Never seen this before. However, SSRS can be a bit "off" at times, so here's a list of things to try. I'm afraid most of these are of the type "Have you tried turning it off and on again?".
Delete the .data files associated with the report.
Duplicate/back-up the report, and try to add the dataset in a fresh, basic tablix to see if that does show data.
Check the hidden property. Don't forget that (for some stupid reason) it's not (like in any other sane product) a Visible Y/N field, but a Hidden Y/N field.
Double check font color and size, etc.
Run the report on your reportserver (as opposed to the preview) to check if that does work.
Use some temporary text boxes to show the actual values of your parameters, to check if they are exactly the same as when you test-run the data set.
Check the code-behind (xml in the rdl) for unexpected filters, hidden property, expressions, etc. in the tablix. Even if you can't quite "read" the RDL, with syntax highlighting you should be able to skim it and extract a lot of info on this.
Check the ExecutionLog2 and other logging stuff to see how many rows are being returned in report runs.
In addition, it would help if you update/edit your question with some more info:
What kind of groupings does the tablix have?
What are the filters on the tablix, row groups, and column groups?
What is the general structure of the dataset, and it's results?
How are the parameters structured and used?
When using temporary tables, SSRS fails to get the metadata. So there are basically 2 ways of letting SSRS know the column names:
Add SET FMTONLY ON. This will retrieve the metadata but it won't display the data.
Go to the DATA tab and click on the Generic query designer and click refresh fields. This will prompt a dialogue box for specifying the parameter value. When we run the query in query designer SSRS gets the schema and the data from the stored procedure. Now the data will be available in preview pane.
I also had a similar issue. In my case, it even occurred without any parameters or anything, just the most simple report you can imagine. It included a table with a single field, no filters were used. I did manage to view some data, but only those lines were shown which did not fit into the cell and thus forced the row height to increase.
My fix for this issue: changing the font or the font size from the standard (size 10, Segoe UI). Then, all data was showing. Changing this back to Segoe UI made the data disappear once again.
I had the same problem. Here is what I found. Here is my code:
DECLARE #tblPigProblems TABLE (
Id INT IDENTITY,
PPId INT,
GaugeColor VARCHAR(25),
FullStartTime VARCHAR(25),
PigSystem VARCHAR(25)
)
IF (1 = 0)
BEGIN
SELECT * FROM #tblPigProblems
END
...
SELECT '#tblPigProblems' [PigProblems],
#p_vchLine [Line],
GaugeColor [Product],
FullStartTime [Start Time],
PigSystem [Pig System]
FROM #tblPigProblems
What I did was to use the initial "SELECT * FROM #tblPigProblems" to ensure that if any error messages were specified in the code before the final select statement returning the dataset, that SSRS was able to determine the fields from the stored procedure. Then, when the results were determined, I assigned an alias to the fields. The problem was that the aliases for the fields did not match the declared field names (ie: the declared field "GaugeColor" did not match the alias "[Product]" I supplied in the select to create the result set. The way that I realized this is that when I refreshed the fields in the Data section of the SSRS report, then displayed the dataset fields, it listed the field names from the table declaration (ie: "GaugeColor"). When I executed the stored procedure within the dataset (clicked on the !), the result set listed in SSRS showed the field aliases (ie: "Product"). Since these didn't match, nothing was displayed in the textbox I had assigned the field to (ie: "=Fields!ColorGauge.Value"). SSRS did not pick up this discrepancy and allowed the report to be created, but no values to be displayed. The fix was simple, replace:
IF (1 = 0)
BEGIN
SELECT * FROM #tblPigProblems
END
with:
IF (1 = 0)
BEGIN
SELECT '#tblPigProblems' [PigProblems],
#p_vchLine [Line],
GaugeColor [Product],
FullStartTime [Start Time],
PigSystem [Pig System]
FROM #tblPigProblems
END
Dan
I had a case where a working report stopped displaying data. I added another table with no formatting, linked to same dataset - verified that the query no longer returned data when passed parameters by SSRS. After investigating, I noticed that my test parameter for a "anchor date" value was formatted as YYYY-MM-DD, and in my updated query, I was making assumptions about the order of the characters in the date parameter (to truncate to YYYY-MM for one join).
I suspected that SSRS may be passing the date in a different format (MM/DD/YY being my current cultural setting for date defaults). So running with that hunch, I changed my SQL logic to work with any date format passed. - e.g. left(convert(date, #anchorDate, 20), 7)
This fixed my problem - the format assumptions that I had tested with (hard coded values to test the query while developing) were bad assumptions. SSRS can pass data in local formats as well - so be sure to watch out for this kind of assumption.
I had the same problem and I tried to check the priorities of my tablix. I solved the problem by changing CANGROW value to FALSE.

Dynamic query creation

I have a scenario wherein with the following details:
I have a form that contains fields like firstname,middle name,lastname,dob,pin,address for Client 1.
Now this form has to cater more than one client . The problem statement is - different clients may require different number of fields to be displayed on front end. For eg: a 2nd client would want - Country field instead of pin, would not require address on the form.
Now when i submit the form , currently i have a constant query which takes values of - firstname,middle name,lastname,dob,pin,address and inserts it into database for Client 1. I want to develop a query in a way that it is created at runtime and inserts only the values that come from the form into the database..
I hope my problem is clear. Can anyone help?????????????
You need to think about why you are doing this.
It will get hideously complex with just person form, add in more and it will balloon big style.
Dynamically building queries isn't particularly complicated, but it's a lot of code to do it.
Just think about each field you want to add to the query and it's type. What if a property on your person record was an image of them.
Do you have a configuration of the form, is the promary key on the record an auto inc, is it a compound key, do you use defaults, are some fields not null. How are you going to bubble back referential integrity exceptions...
Do the all singing all dancing version and basically you reinvent something like the Access IDE....
Personally I'd have a Person object with a set of Person Properties, they would have name, a value and a boolean to say whether they'd been changed.
Once you have teh list of chnaged properties and beacseu you are in the Person object you know the table is persons, it's keyed by an autoinc bigint, gender is mandatory and defaults to Male...
You have a fighting chance.
Your query should use parameters
So it would be say Insert Persons(FirstName, LastName, PIN) Values(#FirstName,#LastName,#PIN)
Then you'd nip through your changed fields and add parameters with same name, type and value.
As I said you can really go to town with this one, may be it's time for a night in though.
This should mean that some fields in your table like address and pin can be empty, in that case you can do without a dynamic query. Just collect all the inputs from your form and insert them into your table. Those form fields that were left empty due to different user needs will consequently have their corresponding field in your table empty. So just list all the needed fields in your table and all the possible input from your form in your insertion query.