Archive for the ‘update statement’ Category

SQL update statement?

April 16, 2010 - 11:14 am 2 Comments

I have 2 tables. I want to insert T1 ( C3, C4) with T2 ( D3, D4) where T1.C5 = ‘09/2010’ with a SQL statements.

T1
—————-
C1 C2 C3 C4 C5
a 1 — — 09/2010
b 4 — — 08/2010
a 1 — — 09/2010

T2
—————-
D1 D2 D3 D4 D5

a 1 10 20 09/2010
b 4 50 40 08/2010
a 1 70 80 09/2010

Final Result table

T1
—————-
C1 C2 C3 C4 C5
a 1 10 20 09/2010
b 4 — — 08/2010
a 1 70 80 09/2010

Try something along the lines of

UPDATE T1
SET C3 = D3
SET C4 = D4
FROM T2 WHERE D1 = C1 AND D5 = ‘09/2010′

Update command is deleting unrelated records?

April 12, 2010 - 3:26 pm 1 Comment

I’m trying to fix a software issue for a client. The client is using our software against an Oracle database. They are attempting to update records in a table via our software interface. The software generates a SQL UPDATE statement appropriately using a unique key field. The record being targeted is appropriately updated.

HOWEVER, another, totally unrelated record, is being deleted. Even if the user has no delete permissions on the table. The record being lost is the last one that would be returned if you sorted the table based on a different (multi-field) key (which isn’t being used in this procedure).

Any thoughts?

Check FOR UPDATE trigger on this table.

mysql update from a text file?

February 19, 2010 - 7:19 am 1 Comment

I am trying to update a field in mysql database. The update statement is long and DOS Command always truncates the last portion. If I paste the statement in a text file, how to execute the file. My mySql is 3.x version. Thanks

IF I understand correctly, just create the update in a plain text file save it with name update.sql (as an example..). Then from the DOS window, or any shell do:

mysql -u user -p databasename < update.sql

It will prompt you for your password.

And that’s it. Be sure to take some time to browsw through mysql docs, also if posible update to a newer version, you are missing a whole lot of stuff with 3.x

Alex

SQL UPDATE STATEMENT NOT WORKING?

February 17, 2010 - 5:27 am 2 Comments

UPDATE TABLENAME as a
SET a.NAME = b.NAME2
FROM TABLENAME2 as b
WHERE
a.ID = b.ID2

What’s wrong, it is not working?

I don’t see anything wrong the the statement alone. What is it not doing? Are you getting errors? Just not updating? Is ID2 the correct field name in TABLENAME2? ID2 seems a little odd. So does NAME2.

If the two tables have different names (ID vs ID2, Name vs Name2) you don’t need the ‘as’ clauses. If they do have the same name, don’t put the 2 after it.

That’s all I can think of without more information.

Good luck.

what does this statement do? void (*update)(Blackboard&);?

February 15, 2010 - 4:12 am 2 Comments

im not sure what exactly is "update" but im sure "Blackboard" is a class. does this statement ring any bell for you? for example in below:
class Xclass{
public:
std::string representation;
const ModuleState* moduleState;
void (*update)(Blackboard&)
void (*create)();
void (*free)();
}

class Xclass{
public:
std::string representation;
const ModuleState* moduleState;
void (*update)(Blackboard&); // missing ;
void (*create)();
void (*free)();
}; // ; was missing

your code would not compile like this:
you need to have a forward declaration for
ModuleState and Blackboard (for example) like this:

class ModuleState;
class Blackboard;

In order to instantiate your class you need to have ModuleState and Blackboard defined somewhere in your code.

update, create, and free are pointers to static functions. Please check further down
The following is an application, of static function pointers used in a class:

class CPtr{
public:
// this is a pointer to a static - non-member - function taking 2 ints as parameters
int (*fct)(int, int);
CPtr( int (*)(int, int) );
};

// this is the static function the CPtr member
// it is passed as a parameter during instantiation
// of the CPtr object.
int max(int iA, int iB)
{
return iA > iB ? iA : iB;
}

// this is the constructor, which takes
// one argument, which is a pointer
// to the function, which should be used
// by the object
CPtr::CPtr(int (*Max)(int iA, int iB))
{
fct = Max;
}

int main(int argc, char* argv[])
{
// This is object a, instantiated with the
// function max. The function prototype
// is matching the declared function
// pointer in CPtr
CPtr a(max);

const int iA = 3, iB = 4;
// this is how the member is invoked
cout << "The bigger number between " << iA << " and " << iB << " is: " << a.fct(iA, iB)<<endl<<endl;
}

where can I found PHP or JavaScript function to execute a statement every specific amount of time ?

February 10, 2010 - 7:07 am 3 Comments

Hi all

where can I found PHP or JavaScript function to execute a statement every specific amount of time ?

for example :
i need to execute a specific function every 30 minuites (like update a DB with a time dependent specific statement ) .. how can i do it ?

thanks

depends. The IDEAL way to handle this would be:

cron

which is its own binary on *NIX systems. I don’t want to presume anything about your system though.

With cron, everything would be done on the server and you wouldn’t need to for example leave a window open executing things.

In PHP, all processing occurs before a response to an HTTP request is sent, so you would need both a PHP page that did the processing and a javascript to call it. This is generally done with AJAX.

Is it possible to combine update and select statements in PHP?

January 23, 2010 - 9:49 am 2 Comments

I have a table containing 2 columns. The first column is already filled. I want to update 2nd column of all records in this table using the values available in ANOTHER table based on the value of the first column of first table. Something like - UPDATE TABLE1 SET COLUMN2OFFIRSTTABLE = SELECT COLUMN2OF2NDTABLE FROM TABLE2 WHERE COLUMN1OFFIRSTTABLE=COLUMN1OF2NDTABLE; or any other command to achieve the same effect??

I don’t think it’s possible to do it the way you’re asking. But why don’t you just separate the queries? It will do the same thing either way.

Hey people, this is an update of my UCAS Personal Statement, please read, comment and give corrections if need?

December 9, 2009 - 4:26 pm 2 Comments

If you read my 2nd last question, you would have noticed that I made a few changes to my statement over here. As much as you comment, please RATE my P.S from 1 to 10

"Science is a subject that I have always been fascinated about, I would like to apply for the Electrical and Electronic Engineering course. Physics and Mathematics are my best subjects; they both play a big role in the course and would be useful to me, as I am able to solve mathematics equations. Also the idea of creating electronic objects like robots, video-game consoles and accessories, large machines and phones really appeals me. Science related studies have been around my family for ages-my father and some of my uncles studied engineering, my maternal grand father studied architecture and my mother has a PhD in medical Science.
Currently, I am attending Barnet College and I am studying BTEC National in Applied Science (I really enjoy the practical side of the course) and GCSE English (retake) with the aim of getting at least an MM Grade (160 UCAS Tariff Points) in the BTEC and a C Grade in the GCSE, respectively. I decided to do both courses because of the inspiration of my recent GCSE achievements; also I knew that participating in the course would make me successful in any science course, like electronics or electrical engineering.
I have some work experience; for example I worked outside the country, in a cybercafe for a month. As a Ticket Clerk, I was responsible for selling out tickets for time limits at which costumers could use the computers as well as helping them out in using the computers, for instance I assisted an elderly man in using his e-mail account. and that lead me to having skills useful to me in the course. I have some computer skills which include knowledge on how to use the Microsoft Office and the internet therefore giving me the ability to do course work with a computer. With other skills like being able to manage my time, I can ensure that I will always be punctual during learning hours, plus my literacy and communication skills can help me in confidently working alongside with lecturers and other students to make better achievements. As well as communication skills, team work is also important when working with fellow students; I am a good team player therefore, that is not a problem for me.
In terms of leisure, I enjoy playing video-games, especially console games- my best genres are football, racing, fighting & adventure, sometimes I have daydreams of making my own video game which brings me back to the reason why I was destined for this course. My best movie genres are action, sci-fi, comedy and at times horror; comic book hero movies like Iron man amaze me. I liked the main character of the movie; Tony Stark, he’s the one I almost wanted to be like- wealthy, confident and he was also into Electronic Engineering, which is why he was able to make his Iron man suit and become a hero.
I enjoy watching football-my favourite club is Arsenal and my favourite national team is Nigeria. My most memorable Arsenal player is Thierry Henry; he earned a record as the highest goal scorer in Arsenal through out the team history, second to Ian Wright and he was one of the players that helped Arsenal to qualify for a UEFA champions’ league Final. I enjoy listening to music; almost any kind of music grabs my attention, even soundtracks from movies and video games, but my best music genre is Rhythm and Bass.
Furthermore, I look forward to the experience, challenges and achievements of higher education. As I have explained, I consider that I have the necessary interest skills and motivation to apply for electronic and electrical engineering. After the degrees, I would like to work in an engineering industry, build machinery for the government or participate in research for new devices. By taking part in this course, I would be fulfilling my career path."

As a very critical University student I have to give this a 2.

I don’t know what University’s your applying for and I won’t write your ps out again (as It already been done) but I will give you comments.

Firstly don’t have words such as "some" in I have ’some’ work experience. Don’t use words that show a lack of what you have. Just say I have work experience and let them be the judge of how much there is.

You also have a grammar mistakes. Phones really appeals TO me. There also a few other mistakes. Just get someone to look over it with it printed out so they can underline all the little mishaps! It’s not a problem. I had a few.. But it does not hurt to have it perfect!

You do not need to list how many UCAS points it is, you can if you think the University admissions teams are idiots, but they should know.

The paragraph on football is not useful to why you want to go to University. I mean If Thierry was applying then maybe, but no. Just say you enjoy football as a sport, watching and playing and say how you will get involved in the University this way.

Your paragraph on leisure is limited. This is your weakest part of your personal statement. It hinders you rather than help. I would word it somewhat like this.

Within my spare time, I enjoy interactive games, specialising in console formats. My favoured genera’s include sports, racing, fighting and adventure based. Moreover my passion for gaming is not limited to just consuming. My goal is to take part in the production of a title, which drives me to the pursuit of Electronic Eng.
I also have an interest in film industry, favouring such genera’s from action to comedy. My favourite however would have to be comic book based movies, such as Iron man.

Something like this. It’s not perfect but please if you do anything don’t say you want to be Iron man. It makes you sound that you are not mature for the course.

Also a question I would ask if I was in admissions is. Why this course? If you want to do computer games. Why not do computer sciences what is based more on software rather than eng. Which is more on the physical side.

Conditional SQL Update Statement?

November 25, 2009 - 5:57 am 3 Comments

I have a table with hundreds of columns where some may be duplicated. What I want to do now is go back and add an index of sorts based on that column. For example:

OrderID
OOP-200221
POP-39808903
POP-39808903
POP-39808903
IIK-3993
IIK-3993
KOL-3939393930

I want to add an ID column that would show something like this:
1 - OOP-200221
1 - POP-39808903
2 - POP-39808903
3 - POP-39808903
1 - IIK-3993
2 - IIK-3993
1 - KOL-3939393930

(I used the dash to seperate the values, I just want the number in the new ID column and the OrderID to remain in the OrderID column.)

Is there a way to do this with a SQL statement?

Thanks in advance!
I’m trying to do this in SQL 2005 through a query. I guess I should have specified that.

I wasn’t able to get the query you supplied to work…

If you use phpMyAdmin, you can simply add a column in the front.
I will give you the SQL query however to add something to the beginning of the table.
Query:
ALTER TABLE `db_name` ADD `id` INT( 3 ) NOT NULL AUTO_INCREMENT FIRST

The FIRST at the end places that column to the beginning.
If you need further help, email me.
Good Luck!

Are you a walking fashion statement or you need a bit updating?

November 9, 2009 - 12:47 am 17 Comments


With me, from one day to the next it changes. One day I might be in "skinny jeans" then I dig the old trusty’s out and go back five years.
So I guess I could use an update or two.