I'm having some problems with a query generated by a program I use. The program make an insert into two different databases on different servers:
INSERT INTO Sumas (codeje, codcta, codpercon, impdeb)
VALUES ('2018', '6311001', 9, -8000)
On the first server, the query works fine, but on the other server, I have a problem with a null value. The complete table:
I assume that if I don't pass the value, one server use the null and the other use blan^k. There is any configuration where I can change this?
Look at the schema for the table and examine the field for a possible default value. If you have the ability to change it, update it so that the two are the same.
Related
We're working with a customer that has a SQL Server of unknown vintage running on a server we do not have direct access to. Our only link is via a DSN name that is the same on every client machine, but we do not know the details of that DSN. I mention this because I think there is a driver issue, and I can't tell you what driver it is.
We are using VBA to do some basic SQL reporting. The problem is that when we are fetching data from a table that has a column called "description", any attempt to retrieve data after that in the select statement will cause the RecordSet to return null values even though there is data in the fields. For instance....
SELECT description, one, two, three FROM tNasty
will cause...
DS!description
to print the expected value, but...
DS!one
will return null (and two and three). Now if all we do is re-arrange the fields to...
SELECT one, two, three, description FROM tNasty
Then all the values work fine!
I copied the data to my own machine's Express instance, and connected to it using a connection string instead of the DSN. Then it works fine no matter what the order is. This seems to imply it's something in that DSN.
Has anyone seen anything like this before? Or have suggestions on how to figure out what those DSN settings may be without being able to see them through the GUI?
I have an SSRS report that populates a parameter with a stored procedure. This query works as expected. When the parameter is used in running the report, the parameter is being truncated. I choose value ABCD, but the report returns values for ABC. The stored procedure I am passing the parameter to runs perfectly in SSMS and returns ABCD data. When I test the query in the query designer or I run the report, I get ABC data. How do I get SSRS to pass in the entire parameter?
Parameters are strings without a set length. There's nothing to truncate your values. Have you checked the values to make sure that the Value and Label are the same?
The label is what you see (ABCD) while the value is what is actually passed in the parameter. I don't know if that would be your problem if it works on your local machine though.
If that doesn't work you can try deleting the parameter and recreating it - it shouldn't work but has before.
I had something like this happen to me before, try going into the stored proc you have and creating an output table for your parameters results to go into that is constant, i.e.
declare #mytable table (returnval varchar(50))
make sure you make one column in the table for the results of your query you will return and make sure you make the data type a varchar with enough pace to hold any possible return selection values. Note: do not use nvarchar as I find this still sometimes truncates the values and cuts things off.
you will want to execute the query the same way for the proc you originally did but this time inserting the values into your temp table i.e.
insert into #mytable
select * from table.name
this will insert all values into your temp table, also this table now has a set value length for all return values that will not change, you could try and do this the same way with the original query by using a set length field for the table the problem is there are many factors that exist that can change this, here are a few examples.
If you have 2 select statements with a union to get results from both that you want to use for final results then each field may have a set length and data type that differs from the other, sql server will give the best data type in the results but when it sends the data over to ssrs it can interpret it differently as another length value unless set.
You may have multiple data types you are using in the return field and ssrs is getting confused which to use i.e. interger values, varchar, text, etc. this sort of reinforces the one above.
Also another possibility is it could be happening on the SSRS side of things and not the proc, but by doing this method you eliminate out one possible cause which is the stored proc.
Also, check in the configuration settings of your report on the back end and make sure that the return value is set from the query as it should be but also make sure that there is no setting specified for a return data type, this sometimes happens if at report design you create the report first and use a static parameter for testing to get the report created first and then you specify later the parameter is a list from a query result set which I have had happen as well.
Finally one good practice each time you make a change to something is to ensure that the report is being generated each time and not showing a cached version of the report which makes it look like nothing changes on the report each time. the way to do this is to close the report each time or when you run the report also try and make sure you hit the reload on the page after you run the report to force a reload to make sure you see the differences each time.
I think if you do all of this you will either find the issue or eliminate it or both as I have so many times.
I have a table to which I would like to add computed column (with values different for each user - needed for permissions).
Problem is that this table is part of Microsoft Dynamics NAV which don't know anything about computed columns.
I've managed how to cheat NAV so that I change the column type after NAV creates it and I can read the data.
Now I'm stuck with inserts.
NAV don't use nullable columns so it always tries to insert default value and SQL Server fails with error on computed column.
I've tried to write INSTEAD OF INSERT trigger but seems that SQL Server is doing the check before it runs the trigger and still fails with error.
Is there any way to force SQL Server to ignore inserted value on computed column?
Personally I wouldn't change the schema of a third-party application, especially a financial system. Instead of changing the tables you could create views - you can even create them in another database if you want - that include your computed column definition, then put your INSTEAD OF triggers on the views and do INSERTs through the views.
I have a SQL Server 2008 database. This database has a stored procedure that will update several records. The ids of these records are stored in a parameter that is passed in via a comma-delimited string. The property values associated with each of these ids are passed in via two other comma-delimited strings. It is assumed that the length (in terms of tokens) and the orders of the values are correct. For instance, the three strings may look like this:
Param1='1,2,3,4,5'
Param2='Bill,Jill,Phil,Will,Jack'
Param3='Smith,Li,Wong,Jos,Dee'
My challenge is, I'm not sure what the best way to actually go about parsing these three CSVs and updating the corresponding records are. I have access to a procedure named ConvertCSVtoTable, which converts a CSV to a temp table of records. So Param1 would return
1
2
3
4
5
after the procedure was called. I thought about a cursor, but then it seems to get really messy.
Can someone tell me/show me, what the best way to address this problem is?
I'd give some thought to reworking the inputs to your procedure. Since you're running SQL 2008, my first choice would be to use a table-valued parameter. My second choice would be to pass the parameters as XML. Your current method, as you already know, is a real headache and is more error prone.
You can use bulk load to insert values to tmp table after that PIVOT them and insert to proper one.
I've got a column in a SQL Server table that is type XML. I want to change multiple values in the XML in a stored proc. I've already found the XML.Modify(...) command and have it working for a single value. Can I change multiple values in the XML in one update command or do I need to do it as multuple update commands?
You will need to use multiple (xmlcol).modify calls - you cannot update multiple bits at once, as far as I know.