We can do it with following code,
if (variablename == undefined){
variablename = 'XYZ';
}
But for some reason, firefox will throws error with above code. So the solution to that problem is,
if(window.variablename == undefined){
window.variablename = 'XYZ';
}
Search This Blog
30 December 2010
29 December 2010
How to insert NULL value in PostgreSQL date column?
The simple query is like,
INSERT INTO table (date_field) VALUES (NULL);
But when we try to run this insert query through PHP application, where we don't know whether the variable is NULL or contain some value, it starts giving error. Here we need to do some programming and query manipulation as shown below,
<?
if(empty($dbDate)) $dbDate = '0000-00-00';
$myQry = "INSERT INTO table (date_field) VALUES (CASE $dbDate WHEN 0 THEN NULL ELSE TO_DATE('{$dbDate}', 'YYYY-MM-DD') END)";
/*Remaining code comes here */
?>
INSERT INTO table (date_field) VALUES (NULL);
But when we try to run this insert query through PHP application, where we don't know whether the variable is NULL or contain some value, it starts giving error. Here we need to do some programming and query manipulation as shown below,
<?
if(empty($dbDate)) $dbDate = '0000-00-00';
$myQry = "INSERT INTO table (date_field) VALUES (CASE $dbDate WHEN 0 THEN NULL ELSE TO_DATE('{$dbDate}', 'YYYY-MM-DD') END)";
/*Remaining code comes here */
?>
Labels:
PHP,
PostgreSQL
28 December 2010
How to Enable Macro in Microsoft Office Excel 2007?
- Open Microsoft Office Excel 2007 Click on Office logo at the very Left hand Top
- Then select "Excel Options", select "Trust Centre" on left hand side and click on "Trust Centre Settings"
- Select "Macro Settings" and then select "Enable all Macros", if Macros are also written in Visual Basics programming, put check before "Trust access to the VBA project object model"
Labels:
Windows Trouble Shooting
26 December 2010
How to find Serial number of machine?
To find out the serial number of the machine, go to windows command prompt and type following command on the command prompt,
IdentifyingNumber Name Vendor
L3ZZ896 5897X7Y LENOVO
Where IdentifyingNumber is Serial number of machine, Name is Productid and Vendor is the name of manufacturer
- Start > cmd
- C:\Users\XYZ > wmic csproduct get identifyingnumber,vendor,name
IdentifyingNumber Name Vendor
L3ZZ896 5897X7Y LENOVO
Where IdentifyingNumber is Serial number of machine, Name is Productid and Vendor is the name of manufacturer
Labels:
Windows Trouble Shooting
22 December 2010
CONCAT_WS for PostgreSQL
PostgreSQL do not have function like CONCAT_WS of MySQL, but writing the query as given below we can do much more...
SELECT ARRAY_TO_STRING(ARRAY[initial, firstname, lastname] , ' ') AS user
FROM users
Same as CONCAT_WS function, the above query will ignore fields which are having NULL values, and return the concatenation of remaining fields. But if your fields contains blank value, modify the above query as given below, to get the proper result
SELECT ARRAY_TO_STRING(ARRAY[
CASE title WHEN '' THEN NULL ELSE title END,
CASE firstname WHEN '' THEN NULL ELSE firstname END,
CASE lastname WHEN '' THEN NULL ELSE lastname END], ' ') AS user
FROM users
SELECT ARRAY_TO_STRING(ARRAY[initial, firstname, lastname] , ' ') AS user
FROM users
Same as CONCAT_WS function, the above query will ignore fields which are having NULL values, and return the concatenation of remaining fields. But if your fields contains blank value, modify the above query as given below, to get the proper result
SELECT ARRAY_TO_STRING(ARRAY[
CASE title WHEN '' THEN NULL ELSE title END,
CASE firstname WHEN '' THEN NULL ELSE firstname END,
CASE lastname WHEN '' THEN NULL ELSE lastname END], ' ') AS user
FROM users
Labels:
PostgreSQL
18 December 2010
Migrate Data from Access 97 to PostgreSQL
To migrate data from Access to PostgreSQL, so many tools are available online. I did try to migrate data with few tools, but no success. I encounter issues with the tables which has boolean fields and with the tables in which access date() and time() function are being used to set default value of a column.
The best way to migrate data from Access to PostgreSQL database, I found is through PostgreSQL ODBC driver. To check how to install and setup PostgreSQL ODBC driver go to Install & Setup PostgreSQL ODBC Driver . Once finished with installation and setup of PostgreSQL ODBC driver, you are ready to migrate the data.
How to migrate data from Access to PostgreSQL using PostgreSQL ODBC?
The best way to migrate data from Access to PostgreSQL database, I found is through PostgreSQL ODBC driver. To check how to install and setup PostgreSQL ODBC driver go to Install & Setup PostgreSQL ODBC Driver . Once finished with installation and setup of PostgreSQL ODBC driver, you are ready to migrate the data.
How to migrate data from Access to PostgreSQL using PostgreSQL ODBC?
- Open the access database, select the table, then click on file, Save As/Export, a “Save As” popup will appear, select “To an external file or database” radio button and click ok.
- Then in the new popup for “Save as type” select “ODBC database”.
- An Export window will appear, change the table name if required, or just click ok.
- “Select Data Source” window will appear, select your PostgreSQL DSN, that you have created as mentioned above. And click ok.
- Selected table will get exported to your postgres database.
Labels:
PostgreSQL
15 December 2010
Install & Setup PostgreSQL ODBC Driver
Install PostgreSQL ODBC Driver
- Download the latest PostgreSQL 32-bit ODBC Driver by choosing a mirror from http://wwwmaster.postgresql.org/download/mirrors-ftpand then navigating to the odbc/versions/msi/ folder. The current version is psqlodbc_08_03_0100.zip which was released Jan-22-2008.
- Unzip psqlodbc_08_03_0100.zip
- Run the psqlodbc.msi file
- Click Start, Control Panel, then switch the control panel to “Classical View”, if it's already not in classical view or select "System and Security" category.
- ODBC located inside Administrative Tools folder. Double click ODBC Data Sources. ODBC Data Source Administrator window displays.
- Select File DSN tab and click Add button, select “PostgreSQL Unicode” from the popup opened.
- Type in a name “pgCon” for "Create New Data Source” and Click Next
- Then Click Finish and fill in relevant server, db, username and password.
- Click the Connection button and uncheck Bools as char as shown in Manager Connection Page 1
- Click the Page 2 button and check True is -1, and uncheck updateable cursors as shown ODBC Manager Connection Pg 2 and then click OK
- A DSN (Data Source) with name “ pgCon ” is created and ready to use...
Labels:
PostgreSQL
Subscribe to:
Posts (Atom)