Hi,
I am creating a Python function which contains a SQL string. When the function is loaded, the SQL table must be updated with the values from my program.
This is all done.
Though I'm stuck at the SQL string. How can i say that I want to update the last record ?
I heard about the LAST command, but it doesnt work with my MS SQL Enterprise manager.
Example:
UPDATE Table SET column = 123 WHERE LAST
7 16099
Hi,
I am creating a Python function which contains a SQL string. When the function is loaded, the SQL table must be updated with the values from my program.
This is all done.
Though I'm stuck at the SQL string. How can i say that I want to update the last record ?
I heard about the LAST command, but it doesnt work with my MS SQL Enterprise manager.
Example:
UPDATE Table SET column = 123 WHERE LAST
I forgot to say. There is an error with python which does not let me use INSERT INTO since there can only be updated 8 values at once
You should have primary key or date in your table then you can update maximum record using a key or a date.
To help you with insert you have to show me what columns you have in a table, datatypes and nullable and insert statement you used.
Thank you.
Irina.
Hi Irina,
Thanks for the reply. I have a primary key. My database is ordered by this numeric primary key.
I don't really need any help on Insert, but i suppose i could show the string anyway. Python or SQL doesn't allow me to insert more than 8 values at once. - sqlStr = """INSERT INTO Pforte (EIN_GEW, KARTEN_NR, AUFLIEGER, SPEDITION, LIEF_NR, LIEFS_GEW, PROD_NR, rezept) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')""" %(Gewicht, KartenNR, KFZ, Spedition, LieferscheinNr, LieferscheinGewicht, ProduktNr, RezeptNr)
I know how to select the last record, but not how to modify it.
selecting:
SELECT TOP 1 *
FROM Pforte
ORDER BY LAUFENDE DESC
Please help
Did you mean you are trying to execute statement like this and it doesn't work?
[PHP]
sqlStr = "INSERT INTO Pforte (EIN_GEW, KARTEN_NR, AUFLIEGER, SPEDITION, LIEF_NR, LIEFS_GEW, PROD_NR, rezept, Gewicht, KartenNR, KFZ, Spedition, LieferscheinNr, LieferscheinGewicht, ProduktNr, RezeptNr) "
sqlStr = sqlStr & "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s' ,'%s','%s','%s','%s','%s','%s')" [/PHP]
I removed some double quotes which I am not sure were for.
If it is not a full list of columns in a table the rest of columns must allow nulls in them. Otherwise insert will not be allowed.
Show me error message you get while executing this statement in SQL:
[PHP]
INSERT INTO Pforte (EIN_GEW, KARTEN_NR, AUFLIEGER, SPEDITION, LIEF_NR, LIEFS_GEW, PROD_NR, rezept, Gewicht, KartenNR, KFZ, Spedition, LieferscheinNr, LieferscheinGewicht, ProduktNr, RezeptNr) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s' ,'%s','%s','%s','%s','%s','%s')[/PHP]
Are there all columns listed here allow character strings?
Do you have rights to all other columns?
hmmm. I am not sure how I got it, but the Insert string seems to work now. It can insert all values at once now. But this was a Python problem and Lol! it was no PHP code. Anyway, the insert string is fine now.
But I still need a code which can update the last record of the database. My python function will submit the data and Inserts it into the database, but later more data has to be submitted and updated in the same record.
INSERT INTO will just add a record to the database but my script doesn't know the primary key number, so i cant refer to a record in my script.
How can I do this ?
If you used statement I provided then I did correct some things that were not correct.
Use following Update statement to update last record:
[PHP]
Update Pforte Set
column_name1 = value,
column_name2 = value
where LAUFENDE = (SELECT TOP 1 LAUFENDE
FROM Pforte
ORDER BY LAUFENDE DESC)[/PHP]
You can write an SQL stored procedure that returns last inserted primary key as an output parameter. This way it would be for sure last inserted record.
In just update last record it could happen that it is not last record that you just inserted.
Good Luck.
If you used statement I provided then I did correct some things that were not correct.
Use following Update statement to update last record:
[PHP]
Update Pforte Set
column_name1 = value,
column_name2 = value
where LAUFENDE = (SELECT TOP 1 LAUFENDE
FROM Pforte
ORDER BY LAUFENDE DESC)[/PHP]
You can write an SQL stored procedure that returns last inserted primary key as an output parameter. This way it would be for sure last inserted record.
In just update last record it could happen that it is not last record that you just inserted.
Good Luck.
Wow! It worked. Thank you very much for the help.
Simon
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Reply via newsgroup |
last post by:
Folks,
When performing an update in mysql (using PHP), can I find out how many
records were matched?
mysql_affected_rows() won't work... and I have the following problem
that I thought I...
|
by: BLUE WATER |
last post by:
Does anyone know how I can see a value in my form field text box ?
I tried to add a text box, but the record source doesn't list the variable
I want to see for each record. The variable is the...
|
by: Mihaly |
last post by:
I want to update a record into a table in SQL Server 2000 database from
C#. This table is used concurently for other users too, and I want to be sure
that from the read of record to the update no...
|
by: sdash |
last post by:
I'm working on a simple formview screen that should update a SQL Server 2000
record. I'm sure there must be something simple wrong, but when I press
update, the screen refreshes and the changes...
|
by: Scotty |
last post by:
I like to have a good insert, update and delete code
The code below sometimes workl ok sometimes doesnt work, what i am doing
wrong??
Sub SaveAny()
Dim command_builder As New...
|
by: komatouch09 |
last post by:
Hi
I am new to visual basic. I write program to navigate & update data from table.
My database is in Informix & use ODBC connection. When I nevigate the data it works properly. When I Update the...
|
by: Bakarre |
last post by:
I have problem in retrieving record from mysql using php form, I was able to retrieve the record, if I edit, the changes is not updated in mysql.
find below my code
<html>
<body>
<?php
$db =...
|
by: daniel aristidou |
last post by:
Hi can anyone help me with the logic of updating records that are selected in a datagrid. Just wanna be sure before i code it all, since its first time im doing this and making sure the logic is...
|
by: Michel Esber |
last post by:
Hi all,
DB2 V8 LUW FP 15
There is a table T (ID varchar (24), ABC timestamp). ID is PK.
Our application needs to frequently update T with a new value for ABC.
update T set ABC=? where ID...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |