Translating MSSQL to MySQL queries

Is it possible to migrate with existing database from MSSQL to MySQL?
I wander very much for application working in WIN32 environment (like wine) that translates queries for MSSQL to MySQL queries I mean the situation if some program would think it works with MSSQL but naturally it will work with MySQL carrying migration from MSSQL database with the same data.
Many WIN32 programs use MSSQL mostly like databank.
You guess I want to try to migrate with my production environment from Windows to Linux with some WIN32 application working. Is it possible?
And I wander if MySQL stable equally comparing to MSSQL and have the same undo features.
Does MySQL provide some WARRANTIES for production use?
Thank you!

Is it possible to migrate with existing database from MSSQL to MySQL?
This is best answered by the MySQL people here:
http://dev.mysql.com/tech-resources/art … osoft.html
Notice that they have a discussion forum on the topic.
And I wander if MySQL stable equally comparing to MSSQL and have the same undo features.
In my experience MySQL is as good (and I think in fact better) but  that also depends on the intended use, server load, etc. so I'll live  it at that. You may want to have other opinions on the matter.
Does MySQL provide some WARRANTIES for production use?
Again let's MySQL speak by temselves:
http://www.mysql.com/support/enterprise_support.html
Hope this helps.
Rick

Similar Messages

  • Trying to transfer image files from mssql to mysql

    Im trying to transfer images from mssql to mysql and for some reason many images are not saved in their entirety i.e. you only get a half to a quarter of the image
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    connMysql = ...
    pstmt = connMysql.prepareStatement( "update ItemList set " +
                        "byteSizeLarge= ?, imageLarge = ? WHERE ID = 'A-044'");
    rs.next()
    int byteSizeLarge = rs.getInt(1);
    InputStream imageLarge = rs.getBinaryStream(2);
    pstmt.setInt(1,byteSizeLarge);
    pstmt.setBinaryStream(2, imageLarge, byteSizeLarge);
    pstmt.executeUpdate();
    the data type in mssql for the image is byteSizeLarge and I set the data type to blob in mysql. thank you all for your time

    no image is > 1mb . You can check it out at
    www.bychance.ca
    Its really strange. Even the small images under
    canvas art sometimes they appear
    sometimes they dont. When I replace the servlet
    .class file they appear for a little while and then
    it stops. Click on the small images to see the largeFrom this latest post of yours, it doesn't seem clear that you know whether it's really a MySQL problem with storing the images or not. This sounds like the symptoms of the problem and that you have somehow determined (whether correctly or erroneously) it to be a database problem. Have you really checked your database to see what it has actually stored there?

  • [SOLVED] MySQL queries

    Hey guys just a quick one.  So I made a sweet script to install a wp from a repo version I have on my server.  From there using SED it makes it it's own new install.  So I was able to do the creating of the database, user, and privileges easily using mysql -u <user> -p<pass> -e "command" for each of those steps.  However here comes where i'm stuck.  So I still need to do these steps
    USE $name;
    UPDATE d3_wp_options SET option_value='http://$domain' WHERE option_name='siteurl';
    UPDATE d3_wp_options SET option_value='$name' WHERE option_name='blogname';
    UPDATE d3_wp_options SET option_value='' WHERE option_name='blogdescription';
    UPDATE d3_wp_options SET option_value='http://$domain' WHERE option_name='home';
    However my issue is if I use the above mentioned format to fire mysql queries in the script it will use $name and then when going to the next one it won't be in that database.  So my next thought was using a sub-script and exporting $name and $domain into that script and from there using those variables in the sub-script and just use the -e mysql command.  Is there an easier way to do this with out having to go into a sub-script, like a way to use mysql -u <user> -p<pass> -e and string all of those commands together?
    Last edited by hauntedbyshadow (2014-07-21 12:36:37)

    I'm not sure I understand your question.
    If you are installing WP which runs in PHP would it not be easier to user PHP to do the installation? That way you could use an embedded procedure in the database and things would be easier.
    I do not think you can open a connection to a DB with SED. Can you? And the only way I can see you keeping tabs on what tables/database you are calling is by having an embedded procedure at the DB level. Not to mention, it would be more secure and faster.
    Just a thought.
    R.

  • Translating SQL from MYSQL to ORACLE with more than one outer join.

    I will translate the following sqlquery from MYSQL to ORACLE:
    SELECT ticket.ticket_no,ticket.ticket_dato,ticket.ticket_subject,ticket.customer_id,customer_name,ticket.ticket_own_read, ticket.department_id, department.department_name, priority_name, tickstat_name, tickettype_name
    FROM customer, ticket left join department
    on ticket.department_id = department.department_id left join priority on ticket.priority_id = priority.priority_id
    left join ticketstatus on ticket.tickstat_id = ticketstatus.tickstat_id
    left join tickettype on ticket.tickettype_id = tickettype.tickettype_id
    where ticket.customer_id = customer.customer_id and customer.owner_id =
    #session.owner_id#
    I have tried in ORACLE with:
    SELECT ticket.ticket_no,ticket.ticket_dato,ticket.ticket_subject,ticket.customer_id,customer_name,ticket.ticket_own_read, ticket.department_id, department.department_name, priority_name, tickstat_name, tickettype_name
    FROM customer, ticket ,department, priority, ticketstatus, tickettype
    where
    ticket.department_id(+) = department.department_id and
    ticket.priority_id(+) = priority.priority_id and
    ticket.tickstat_id(+) = ticketstatus.tickstat_id and
    ticket.tickettype_id(+) = tickettype.tickettype_id and
    ticket.customer_id = customer.customer_id and customer.owner_id = #session.owner_id#
    I get an error:
    MERANT][ODBC Oracle driver][Oracle]ORA-01417: a table may be outer joined to at most one other table
    How do I translate the code to ORACLE?

    I think that your syntax is wrong. The (+) operator should be on the right hand table column, not the left hand table column if you want all rows on the left hand table column. If this syntax is really what you want, you can create underlying views for each join condiction.

  • Wierd behavior from MySQL queries

    I have a really frustrating problem in my JSP app that only seems to be occuring sporadically... I have to deploy it on an NT machine that is available right now. I'm using Tomcat/MySQL. I've had it on a W2000 machine and it has worked fine. To complicate things, the NT that it is on does have a proxy server that it must go through...it doesn't seem to want to work during the day, but in the evenings (presumably less traffic?), it has yet to fail me.
    The part of the app that won't update properly is responsible for letting people sign into an office cube daily, updating a seat table in the MYSQL database. It 1st checks to see if the person is assigned to another seat, and deletes that entry if they are. It then updates the seat table, replacing '0' (meaning no one's sitting here) with the person's emp_id. Here's the code for these 2 methods in the seat bean (with session scope):
    //1st method called...removes old entries...
    public void checkAndRemove(int newEmpId)
    throws SQLException {
    int oldSeat = 0;
    try{
    Connection conn = connectionPool.getConnection();
    Statement qs = conn.createStatement();
    ResultSet rs = qs.executeQuery("SELECT id FROM seat WHERE" +
    " id <> " + this.id + " AND emp_id = " + newEmpId +
    " AND editable = " + QUOTE + "y" + QUOTE);
    if(rs.next()) {
    oldSeat = rs.getInt(1);
    rs.close();
    qs.close();
    if(oldSeat > 0) {
    qs = conn.createStatement();
    rs = qs.executeQuery("SELECT COUNT(emp_id) FROM seat WHERE " +
    "id = "+ oldSeat);
    int cnt = rs.getInt(1);
    rs.close();
    qs.close();
    Statement us = conn.createStatement();
    if (cnt > 1) { //Is there more than 1 person at this old seat?
    //If so, we can delete this entry...
    us.executeUpdate("DELETE FROM seat" +
    " WHERE id = " + oldSeat + " AND emp_id = " + newEmpId);
    else {
    us.executeUpdate("UPDATE seat SET emp_id = 0,note= " + QUOTE + " " + QUOTE + " WHERE id = " + oldSeat + " AND emp_id = " + newEmpId);
    us.close();
    connectionPool.close(conn);
    catch(SQLException ex) {
    ex.printStackTrace();
    throw ex;
    //2nd method called, updates the seat with new emp...
    /**updateSeat updates seat information */
    public void updateSeat(int newEmpId, String newNote)
    throws SQLException {
    java.util.Date dt = new java.util.Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String timestamp = sdf.format(dt);
    newNote = escape(newNote); //escape any ' in the text...
    try{
    Connection conn = connectionPool.getConnection();
    Statement us = conn.createStatement();
    us.executeUpdate("UPDATE seat SET " +
    " emp_id= " + newEmpId + COMMA +
    "Note= " + QUOTE + newNote + QUOTE + COMMA +
    "Timestamp= " + QUOTE + timestamp + QUOTE +
    "WHERE seat.id = " + this.id + "AND seat.emp_id = " + this.empId);
    us.close();
    connectionPool.close(conn);
    catch(SQLException ex) {
    ex.printStackTrace();
    throw ex;
    The seat table has a primary key of id/emp_id.
    Like I said, these queries have worked fine on a different installation, and they work sporadically on this one. Any clues about this? Could some sort of 'timeout' be occuring and not throwing any errors?
    Any ideas/help would be greatly appreciated...
    Thanks, Mike

    Sorry. Let me clarify... While this app fails to properly insert into the database, the rest of the app functions as normal.
    Basically, when I click on a hotspot, I open a small window with javaScript. The window has a form that I fill out with emp info, then I submit it and it closes. Then, when someone clicks on that hotspot, the record that should have been created displays...
    This works some of the time, but when it doesn't, it simply displays a blank form, and based on a report run on another page, I know that it never inserted/updated the database. But never any error messages, etc.
    Mike

  • Weird problem with mysql query and data table buttons !!!!

    Hi,
    I'm using jsc 2 update 1 on windows and mysql 4.1 . I have a page with a data table. One column of the data table contains "Details" buttons.
    Source query for the table is :
    SELECT tbl_tesserati.idtbl_tesserati idTesserato,
    tbl_tesserati.num_tessera,
    tbl_tesserati.nome,
    tbl_societa.codice_meccanografico
    FROM tbl_tesserati
    INNER JOIN tbl_rel_tesserato_discipline_societa ON tbl_tesserati.idtbl_tesserati = tbl_rel_tesserato_discipline_societa.id_tesserato
    INNER JOIN tbl_cariche ON      tbl_rel_tesserato_discipline_societa.id_carica = tbl_cariche.idtbl_cariche
    INNER JOIN tbl_qualifiche ON      tbl_rel_tesserato_discipline_societa.id_qualifica = tbl_qualifiche.idtbl_qualifiche
    INNER JOIN tbl_discipline ON      tbl_rel_tesserato_discipline_societa.id_disciplina = tbl_discipline.idtbl_discipline
    INNER JOIN tbl_societa ON      tbl_rel_tesserato_discipline_societa.id_societa = tbl_societa.idtbl_societa
    LEFT JOIN tbl_province ON tbl_societa.provincia_sede_sociale = tbl_province.idtbl_province
    LEFT JOIN tbl_comuni ON tbl_societa.comune_sede_sociale = tbl_comuni.idtbl_comuni
    LEFT JOIN tbl_rel_tesserato_discipline_praticate ON tbl_rel_tesserato_discipline_praticate.tessera_id=
    tbl_rel_tesserato_discipline_societa.idtbl_rel_tesserato_discipline
    LEFT JOIN tbl_discipline_praticate ON tbl_discipline_praticate.idtbl_disciplina_praticate=tbl_rel_tesserato_discipline_praticate.disciplina_praticata_id
    WHERE
    tbl_tesserati.cognome LIKE ?
    AND tbl_tesserati.nome LIKE ?
    AND tbl_rel_tesserato_discipline_societa.id_societa LIKE ?
    AND tbl_tesserati.idtbl_tesserati LIKE ?
    AND tbl_cariche.idtbl_cariche LIKE ?
    AND tbl_qualifiche.idtbl_qualifiche LIKE ?
    AND tbl_tesserati.data_nascita >= ?
    AND tbl_tesserati.data_nascita<= ?
    AND tbl_discipline.idtbl_discipline LIKE ?
    AND codice_affiliazione LIKE ?
    AND tbl_societa.denominazione LIKE ?
    AND YEAR(tbl_rel_tesserato_discipline_societa.data_scadenza) LIKE ?
    AND (tbl_province.nome LIKE ? OR tbl_province.nome IS NULL)
    AND ( tbl_comuni.nome LIKE ? OR tbl_comuni.nome IS NULL)
    The tbl_tesserati.data_nascita is a mysql date field.
    The click event handler code for the "Details" Button is:
    public String btnModificaTesserato_action() {
            try{
                TableRowDataProvider rowData= (TableRowDataProvider)getBean("currentRowTesserati");
                getRequestBean1().setId_tesserato((Long)rowData.getValue("idTesserato"));          
            } catch(Exception ex) {
                log("errore nella query",ex);
            return "dettaglioTesseratoSocieta";
        }When i run the project and open the page the table is correctly rendered and populated with some rows. But when i click on details button nothing happens, the page is simply reloaded.
    If i set a breakpoint in the code line   TableRowDataProvider rowData= (TableRowDataProvider)getBean("currentRowTesserati");the debbuger does not stop the code execution ! As if the button was never clicked!
    I tried to modify the source query to :
    SELECT tbl_tesserati.idtbl_tesserati idTesserato,
    tbl_tesserati.num_tessera,
    tbl_tesserati.nome,
    tbl_societa.codice_meccanografico
    FROM tbl_tesserati
    INNER JOIN tbl_rel_tesserato_discipline_societa ON tbl_tesserati.idtbl_tesserati = tbl_rel_tesserato_discipline_societa.id_tesserato
    INNER JOIN tbl_cariche ON      tbl_rel_tesserato_discipline_societa.id_carica = tbl_cariche.idtbl_cariche
    INNER JOIN tbl_qualifiche ON      tbl_rel_tesserato_discipline_societa.id_qualifica = tbl_qualifiche.idtbl_qualifiche
    INNER JOIN tbl_discipline ON      tbl_rel_tesserato_discipline_societa.id_disciplina = tbl_discipline.idtbl_discipline
    INNER JOIN tbl_societa ON      tbl_rel_tesserato_discipline_societa.id_societa = tbl_societa.idtbl_societa
    LEFT JOIN tbl_province ON tbl_societa.provincia_sede_sociale = tbl_province.idtbl_province
    LEFT JOIN tbl_comuni ON tbl_societa.comune_sede_sociale = tbl_comuni.idtbl_comuni
    LEFT JOIN tbl_rel_tesserato_discipline_praticate ON tbl_rel_tesserato_discipline_praticate.tessera_id=
    tbl_rel_tesserato_discipline_societa.idtbl_rel_tesserato_discipline
    LEFT JOIN tbl_discipline_praticate ON tbl_discipline_praticate.idtbl_disciplina_praticate=tbl_rel_tesserato_discipline_praticate.disciplina_praticata_id
    WHERE
    tbl_tesserati.cognome LIKE ?
    AND tbl_tesserati.nome LIKE ?
    AND tbl_rel_tesserato_discipline_societa.id_societa LIKE ?
    AND tbl_tesserati.idtbl_tesserati LIKE ?
    AND tbl_cariche.idtbl_cariche LIKE ?
    AND tbl_qualifiche.idtbl_qualifiche LIKE ?
    AND tbl_tesserati.data_nascita >= ?
    OR tbl_tesserati.data_nascita<= ?
    AND tbl_discipline.idtbl_discipline LIKE ?
    AND codice_affiliazione LIKE ?
    AND tbl_societa.denominazione LIKE ?
    AND YEAR(tbl_rel_tesserato_discipline_societa.data_scadenza) LIKE ?
    AND (tbl_province.nome LIKE ? OR tbl_province.nome IS NULL)
    AND ( tbl_comuni.nome LIKE ? OR tbl_comuni.nome IS NULL)
    Using this query everything works well !! The click handler works and the debugger too !!
    I changed only the AND in OR !!!
    I also tried to change mysql-x-x-connector driver but without solving my problem.
    Can someone help me ?
    Thanks
    Giorgio

    You'll find that it is more to do with the way MySql deals with dates than anything else! Depending on how your date field is setup, then try using a BETWEEN statement for those 2 lines in your first query e.g.
    AND ( tbl_tesserati.data_nascita BETWEEN ? AND ?)
    The date column needs to be in the ISO format to work. If you examine your second query output, you might discover that the output is only going to refer to one parameter (probably the OR one). Did you manage to view the output logs from the application server? You would have got an idea from there with a message like stating a conversion error'.
    Alternatively, you could try using the to_days() function and convert it directly to a number which would be a lot easier to deal with. For example:
    AND to_days(tbl_tesserati.data_nascita >= ? )
    AND to_days( tbl_tesserati.data_nascita<= ? )
    Or try the BETWEEN version with to_days() and see what you get.
    More info about date formatting (v5) here:
    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_to-days
    Before I forget, sometimes you may need to treat dates as Strings rather 'Long' as you did.
    As a matter of interest, did you try your query in a different piece of software?
    If my queries are a little more complicated, I tend to try MySql queries out in the free MySql query browser and also double check in another to verify certain issues. I found it easier to develop SQL in a seperate program then import the final version to JSC making the required modifications for parameters.
    Message was edited by:
    aerostra

  • How Can I use Mysql's  PROCEDURE by Java Can you give me sample???

    �������^���������������H�iBEGIN�`END�u���b�N�j�@��TOP
    ORACLE�@MSSQL�@SSA�@MySQL�@
    ���{�I���������������������������B
    MySQL�������A ORACLE��MSSSQL��������������BEGIN�`END�u���b�N�����s�������������������������B
    ���������s�������������K���X�g�A�h�v���O�����������R���p�C�������K�v�����������B
    �i�����F�������������������A���w�E�������������K�r�����������j
    --drop PROCEDURE sp_hoge;
    --�f���~�^�����X��������
    delimiter //
    CREATE PROCEDURE sp_hoge()
    DETERMINISTIC
    BEGIN
    /* �������� */
    DECLARE mystr VARCHAR(20);
    DECLARE mycnt INTEGER(2);
    /* �l������ */
    SET mycnt = 0;
    SET mystr = '����';
    /* IF�� */
    IF mycnt = 0 THEN
    SET mystr = '�����Q';
    select mystr;
    ELSE
    select '�����R';
    END IF;
    /* CASE�� */
    CASE extract(month from now())
    WHEN 1 THEN SET mystr = '1��';
    WHEN 2 THEN SET mystr = '2��';
    WHEN 3 THEN SET mystr = '3��';
    WHEN 4 THEN SET mystr = '4��';
    ELSE SET mystr = '1�`4�����O';
    END CASE;
    select mystr;
    /* WHILE-LOOP */
    WHILE mycnt <= 5 DO
    SET mycnt = mycnt + 1;
    select mycnt;
    END WHILE;
    /* BEGIN-END�u���b�N������SELECT�������s */
    /* PROCEDURE�������\�iFUNCTION���������������j */
    select * from help_topic;
    END//
    delimiter ;
    --�X�g�A�h�v���V�[�W�����s
    call sp_hoge();
    �X�g�A�h�v���V�[�W�����T���v���i�J�[�\�����g�p������LOOP�����j�@��TOP
    ORACLE�@MSSQL�@SSA�@MySQL�@
    �J�[�\�����g�p����LOOP�������T���v�������B
    �����p�����[�^���w�����������������Y�������������������A���E���w�X�^�b�t�x�������������A�����������w�c���X�^�b�t�F�x���\���������B
    --drop PROCEDURE sp_hoge;
    --�f���~�^�����X��������
    delimiter //
    CREATE PROCEDURE sp_hoge(inum INTEGER(3))
    DETERMINISTIC
    BEGIN
    /* �������� */
    /* �J�[�\���g�p�����f�[�^�L�����f���g�p */
    DECLARE done INT DEFAULT 0;
    /* �������O������ */
    DECLARE v_mystr VARCHAR(20);
    /* �J�[�\���g�p�� */
    DECLARE v_empnm VARCHAR(40);
    DECLARE v_job VARCHAR(20);
    /* �J�[�\������ �� �����������������`���� */
    DECLARE cur1 CURSOR FOR
    select empnm,job from kemp where deptno = inum;
    /* �f�[�^��������LOOP�E�o�p���������� */
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
    /* �J�[�\���I�[�v�� */
    OPEN cur1;
    /* LOOP */
    LOOPPROC:REPEAT
    FETCH cur1 INTO v_empnm,v_job;
    IF NOT done THEN
    IF v_job = '�X�^�b�t' THEN
    SET v_mystr = '�c���X�^�b�t�F';
    ELSE
    SET v_mystr = '';
    END IF;
    select CONCAT(v_mystr,v_empnm);
    /* ������������LOOP���E�o����������LEAVE�� */
    /* LEAVE LOOPPROC; */
    END IF;
    UNTIL done END REPEAT;
    /* �J�[�\���N���[�Y */
    CLOSE cur1;
    END//
    --�f���~�^���Z�~�R�����i�f�t�H���g�j������������
    delimiter ;
    --�X�g�A�h�v���V�[�W�����s
    call sp_hoge(1);
    12.2. Control Flow Functions
    CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result ...] [ELSE result] END
    CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END
    The first version returns the result where value=compare_value. The second version returns the result for the first condition that is true. If there was no matching result value, the result after ELSE is returned, or NULL if there is no ELSE part.
    mysql> SELECT CASE 1 WHEN 1 THEN 'one'
    -> WHEN 2 THEN 'two' ELSE 'more' END;
    -> 'one'
    mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
    -> 'true'
    mysql> SELECT CASE BINARY 'B'
    -> WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
    -> NULL
    The default return type of a CASE expression is the compatible aggregated type of all return values, but also depends on the context in which it is used. If used in a string context, the result is returned as a string. If used in a numeric context, then the result is returned as a decimal, real, or integer value.
    Note: The syntax of the CASE expression shown here differs slightly from that of the SQL CASE statement described in Section 17.2.10.2, �gCASE Statement�h, for use inside stored routines. The CASE statement cannot have an ELSE NULL clause, and it is terminated with END CASE instead of END.
    IF(expr1,expr2,expr3)
    If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used.
    mysql> SELECT IF(1>2,2,3);
    -> 3
    mysql> SELECT IF(1<2,'yes','no');
    -> 'yes'
    mysql> SELECT IF(STRCMP('test','test1'),'no','yes');
    -> 'no'
    If only one of expr2 or expr3 is explicitly NULL, the result type of the IF() function is the type of the non-NULL expression.
    expr1 is evaluated as an integer value, which means that if you are testing floating-point or string values, you should do so using a comparison operation.
    mysql> SELECT IF(0.1,1,0);
    -> 0
    mysql> SELECT IF(0.1<>0,1,0);
    -> 1
    In the first case shown, IF(0.1) returns 0 because 0.1 is converted to an integer value, resulting in a test of IF(0). This may not be what you expect. In the second case, the comparison tests the original floating-point value to see whether it is non-zero. The result of the comparison is used as an integer.
    The default return type of IF() (which may matter when it is stored into a temporary table) is calculated as follows:
    Expression Return Value
    expr2 or expr3 returns a string string
    expr2 or expr3 returns a floating-point value floating-point
    expr2 or expr3 returns an integer integer
    If expr2 and expr3 are both strings, the result is case sensitive if either string is case sensitive.
    Note: There is also an IF statement, which differs from the IF() function described here. See Section 17.2.10.1, �gIF Statement�h.
    IFNULL(expr1,expr2)
    If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used.
    mysql> SELECT IFNULL(1,0);
    -> 1
    mysql> SELECT IFNULL(NULL,10);
    -> 10
    mysql> SELECT IFNULL(1/0,10);
    -> 10
    mysql> SELECT IFNULL(1/0,'yes');
    -> 'yes'
    The default result value of IFNULL(expr1,expr2) is the more �ggeneral�h of the two expressions, in the order STRING, REAL, or INTEGER. Consider the case of a table based on expressions or where MySQL must internally store a value returned by IFNULL() in a temporary table:
    mysql> CREATE TABLE tmp SELECT IFNULL(1,'test') AS test;
    mysql> DESCRIBE tmp;
    -------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    -------------------------------------------+
    | test | char(4) | | | | |
    -------------------------------------------+
    In this example, the type of the test column is CHAR(4).
    NULLIF(expr1,expr2)
    Returns NULL if expr1 = expr2 is true, otherwise returns expr1. This is the same as CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END.
    mysql> SELECT NULLIF(1,1);
    -> NULL
    mysql> SELECT NULLIF(1,2);
    -> 1
    Note that MySQL evaluates expr1 twice if the arguments are not equal.
    Previous / Next / Up / Table of Contents
    User Comments
    Posted by I W on July 12 2005 5:52pm [Delete] [Edit]
    Don't use IFNULL for comparisons (especially not for Joins)
    (example:
    select aa from a left join b ON IFNULL(a.col,1)=IFNULL(b.col,1)
    It's terrible slow (ran for days on two tables with approx 250k rows).
    Use <=> (NULL-safe comparison) instead. It did the same job in less than 15 minutes!!
    Posted by [name withheld] on November 10 2005 12:12am [Delete] [Edit]
    IFNULL is like oracle's NVL function (these should help people searching for NVL() ..)
    Posted by Philip Mak on May 26 2006 7:14am [Delete] [Edit]
    When using CASE, remember that NULL != NULL, so if you write "WHEN NULL", it will never match. (I guess you have to use IFNULL() instead...)
    Posted by Marc Grue on June 24 2006 2:03pm [Delete] [Edit]
    You can ORDER BY a dynamic column_name parameter using a CASE expression in the ORDER BY clause of the SELECT statement:
    CREATE PROCEDURE `orderby`(IN _orderby VARCHAR(50))
    BEGIN
    SELECT id, first_name, last_name, birthday
    FROM table
    ORDER BY
    -- numeric columns
    CASE _orderby WHEN 'id' THEN id END ASC,
    CASE orderby WHEN 'desc id' THEN id END DESC,
    -- string columns
    CASE orderby WHEN 'firstname' THEN first_name WHEN 'last_name' THEN last_name END ASC,
    CASE orderby WHEN 'descfirst_name' THEN first_name WHEN 'desc_last_name' THEN last_name END DESC,
    -- datetime columns
    CASE _orderby WHEN 'birthday' THEN birthday END ASC,
    CASE orderby WHEN 'desc birthday' THEN birthday END DESC;
    END
    Since the CASE expression returns the "compatible aggregated type of all return values", you need to isolate each column type in a separate CASE expression to get the desired result.
    If you mixed the columns like
    CASE _orderby
    WHEN 'id' THEN id
    WHEN 'first_name' THEN first_name
    ...etc...
    END ASC
    .. both the id and first_name would be returned as a string value, and ids would be sorted as a string to '1,12,2,24,5' and not as integers to '1,2,5,12,24'.
    Note that you don't need a "ELSE null" in the CASE expressions, since the CASE expression automatically returns null if there's no match. In that case, you get a "null ASC" in your ORDER BY clause which doesn't affect the sort order. If for instance orderby is 'descfirst_name', the ORDER BY clause evaluates to:
    ORDER BY null ASC, null DESC, null ASC, first_name DESC, null ASC, null DESC
    Effectively the same as "ORDER BY first_name DESC". You could even add a new set of CASE expressions for a second order column (or more..) if you like.
    Add your own comment.

    What is that post supposed to be?

  • CREATING A SEARCH IN JAVA USING MYSQL QUERY

    How do i create a seach in java using mysql queries. The search need to be like a good type one, whereby a category is typed and the results obtained via the search system using jtable.
    Thank you.

    Read the tutorial on [url http://java.sun.com/docs/books/tutorial/]JDBC Database Access.
    Read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]How to Use Tables.
    Put the two together and you come up with something like [url http://forum.java.sun.com/thread.jsp?forum=57&thread=497641]this.

  • Bug in CF11 regarding Query of queries syntax?

    So I have decided to try CF11 because of an official outstanding CF10 bug.
    Once I installed CF11, I get an error when running code like this:
    <cfquery name="LOCAL.stat_questions" datasource="#APPLICATION.dsn#">
         SELECT     survey_questionID
         FROM     tbl_survey_questions
    </cfquery>
    <cfset LOCAL.this_statID = 1>
    <cfquery name="LOCAL.subset" dbtype="query">
         SELECT     survey_questionID
         FROM          [LOCAL].stat_questions
         WHERE     survey_questionID = <cfqueryparam cfsqltype="cf_sql_numeric" value="#LOCAL.this_statID#">
    </cfquery>
    The error I receive is: "Query Of Queries syntax error.
      Encountered ";. "
    If I remove the semi-colon... No error! Is this a bug, or was the semi-colon always bad, but just ignored?
    Thanks

    I just always put it in out of habit from typing out actual MySQL queries (non QoQ). Never was a problem and I always did it. Now running CF11... it requires fixing. Thought it was strange.
    I actually didn't even notice that the semi-colons weren't required in QoQ until I ran into this CF11 bug. I also notice the semi-colon isn't necessary for a MySQL query either in cfquery! Seems weird that it accepts them, but isn't required. Just ignores them?

  • Creating a connection to a mysql database

    New to CQ5.
    Version: CQ5_5
    Running a local instance on my desktop.
    Trying to connect to localhost:3306 mysql database
    I downloaded the mysql driver and used the instructions here to create and build an OSGI bundle.
    http://cq-ops.tumblr.com/post/21893960212/how-to-turn-a-jdbc-driver-jar-into-an-osgi-bundl e-jar
    Next, I followed instructions here to create a osgiconfig node, populate it and update my component jsp accordingly.
    http://dev.day.com/docs/en/cq/current/developing/jdbc.html?cq_ck=1362183869402#comments-nf fb-unsuccessfullyspent
    On my page - I see the error message
    No data source found with name 'testdb' (after asking 0 providers)
    Any likely gotchas that I might be missing?
    If you have got it working and can just describe the steps you used, I could give that a try too.
    Any pointers are welcome.
    Thanks,

    Hi Andrew,
    check out this <a href="http://developers.sun.com/product/jdbc/drivers">site</a>, maybe you find a suitable driver there? The SAP Press and Helpfiles say, that connecting to a microsoft SQL Database is possible.
    In our portal I found a MSsql jdbc driver installed, with sucessful connection test to northwind-database. Unfortunately, I cannot find out what driver we used.
    If you still don't find a driver, I will ask my colleague if he remembers.
    Best Regards, Benni
    Message was edited: Sorry, I meant MSsql, not mysql. We have a MSSQL-JDBC-System defined, with working connection.

  • Test database queries in dreamweaver

    Hi,
    I have dreamweaver MX and it's nice to write PHP code with
    MySql queries but I have always wondered if it is possible to
    include a PHP server and MySql server in Dreamweaver so that one
    can test the page offline before uploading it to the real server.
    I know one can install external PHP and MySql servers, but
    that might be a little trouble for me.
    Please let me know if this has been included in later
    versions, or might be included in future ones.
    Best Regards,
    Mario Mansour

    > I know one can install external PHP and MySql servers,
    but that
    might be a
    > little trouble for me.
    > Please let me know if this has been included in later
    versions, or
    might be
    > included in future ones.
    Take a look at
    http://www.wampserver.com/en/
    It really does make installation of PHP and mySQL very easy.
    There is none of this built in to DW, and I doubt there ever
    will be.
    E. Michael Brandt
    www.divaHTML.com
    divaPOP : standards-compliant popup windows
    divaGPS : you-are-here menu highlighting
    divaFAQ : FAQ pages with pizazz
    www.valleywebdesigns.com
    JustSo PictureWindow
    JustSo PhotoAlbum

  • MYSQL variable issues

    When creating a record set in a php document Dreamweaver
    seems to incorrectly wrap the order by variable in single quotes.
    For example at run time Dreamweaver returns the MySql statement
    select * from table order by 'var'
    This does not order the output. It should be
    select * from table order by var (no quotes on the var)
    Is there some fix for this or is anyone experiencing this
    issue?
    Thanks
    Wally

    There appears to be a glitch in the DW conversion of variable
    names when creating mysql queries in a php document.
    DW uses the following function to strip slashes and escape
    special characters when creating the query. Unfortunately this
    function also escapes the sort and order variables in the mysql
    statement - which places single quotes around the variables and
    makes them inoperable. This does not work.
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType,
    $theDefinedValue = "", $theNotDefinedValue = "")
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue)
    : $theValue;
    $theValue = function_exists("mysql_real_escape_string") ?
    mysql_real_escape_string($theValue) :
    mysql_escape_string($theValue);
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) .
    "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue :
    $theNotDefinedValue;
    break;
    return $theValue;
    I was able to fix this problem by inserting an additional
    variable type into the function definition which then allows for
    the sort and order vars to be defined as 'other' and then passed
    without the enclosing single quotes yet still check for special
    characters. This works
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType,
    $theDefinedValue = "", $theNotDefinedValue = "")
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue)
    : $theValue;
    $theValue = function_exists("mysql_real_escape_string") ?
    mysql_real_escape_string($theValue) :
    mysql_escape_string($theValue);
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) .
    "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue :
    $theNotDefinedValue;
    break;
    case "other":
    $theValue = ($theValue != "") ? $theValue : "NULL";
    break;
    return $theValue;

  • Leopard PHP MySQL socket problems

    I'm running a default Mac OS X 10.5 Apache2 installation locally, with PHP and MySQL tacked on. I'm running into some trouble running MySQL queries from PHP, namely:
    Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'
    It appears that PHP was compiled with the configuration command '--with-mysql-sock=/var/mysql' but in Terminal the mysqladmin binary reports the UNIX socket as /tmp/mysql.sock. A check reveals that there is indeed a /tmp/mysql.sock, but no /var/mysql/mysql.sock. This appears to be one of those directory differences between Darwin and the standard MySQL distribution.
    Anyhow, I really don't know the best way to attempt to patch this up even after reading suggestions in the MySQL manual. Setting up an option file for mysql to point to /var/mysql didn't improve matters, nor did explicitly setting socket settings in my PHP config file.
    I'm more of a front-end developer not well versed in back end configuration jazz, so any input would be appreciated.

    the other way to fix this is to edit /etc/php.ini and set the following:
    mysql.default_port = /tmp/mysql.sock
    mysqli.default_port = /tmp/mysql.sock
    mysql.default_sock = /tmp/mysql.sock
    mysqli.default_sock = /tmp/mysql.sock

  • VC over a mysql database - Anbody done it?

    Hi there,
    I wish to create 2 JDBC connections to allow me to use SQL server over Microsoft SQL 2000 and mysql
    I have successfully created the microsoft connection for BI_JDBC and the Portal JDBC (Factory Class)
    However I am having difficulties creating a successful connection to the mysql database.
    If I checked the wiki and it refered me to a JDBC driver search. I did not find a MYSQL compatible driver at all.
    I have taken my chances with http://dev.mysql.com/downloads/connector/j/3.0.html
    and tried versions 3,  3.1 and 5.0 to no avail. I have mapped using an administrator  password.
    Searching SDN I cannot see reference to anyone successful creating a mysql connection and all the SAP examples are MS, Oracle DB2 or MaxDB
    Am I flogging a dead horse or is it possible? EP7.0 nw2004s SP10
    Thanks
    Andrew

    Hi Andrew,
    check out this <a href="http://developers.sun.com/product/jdbc/drivers">site</a>, maybe you find a suitable driver there? The SAP Press and Helpfiles say, that connecting to a microsoft SQL Database is possible.
    In our portal I found a MSsql jdbc driver installed, with sucessful connection test to northwind-database. Unfortunately, I cannot find out what driver we used.
    If you still don't find a driver, I will ask my colleague if he remembers.
    Best Regards, Benni
    Message was edited: Sorry, I meant MSsql, not mysql. We have a MSSQL-JDBC-System defined, with working connection.

  • Migrating from mysql to hsql

    I am trying to migrate my webapplication from mysql to hsql.
    Is there any tool for doing this? (converting mysql queries to hsql queries)

    I don't think there are any tools for that. If your queries are adhering to the general SQL standard (I don't know what that is called), there should not be any problem. If you are using any DB specific functions, search for their equivalent and replace them.

Maybe you are looking for