Archive

Posts Tagged ‘isnull’

Sql Scripts – Simple Stuff

September 28th, 2009 Comments off

I have a Volusion.com website for ecommerce. They offer sql abilities for processing data. I need someone who can write simple scripts to do various import/exports of data.

I need sql that will write out cvs data files for differnet shopping websites. Google (see below), Amazon, Ebay and others to be determined.

The example script is for Google. However, I wish to make it only export for specific products (flagged).

I will generally want a sql in a day or two.

Example:
SELECT
p.ProductCode AS id
, p.ProductName AS [stripHTML-title]
, IsNull(pe.Google_Product_Type,’n/a’) AS product_type
, IsNull(pe.SalePrice,pe.ProductPrice) AS price
, IsNull(pe.ProductManufacturer,’n/a’) AS brand
, IsNull(pe.ProductCondition,’NEW’) AS condition
, CONVERT(VARCHAR(10), (GETDATE() + 30),120) AS expiration_date
, pd.ProductDescription AS [stripHTML-description]
, ‘Config_FullStoreURLConfig_ProductPhotosFolder/’ + p.ProductCode + ‘-2.jpg’ AS image_link
, ‘Config_FullStoreURLProductDetails.asp?ProductCode=’ + p.ProductCode + ‘&click=2′ AS link

FROM Products p
INNER JOIN Products_Descriptions pd ON p.ProductID = pd.ProductID
INNER JOIN Products_Extended pe ON pd.ProductID = pe.ProductID
WHERE (p.IsChildOfProductCode is NULL OR p.IsChildOfProductCode = ”)
AND (p.HideProduct is NULL OR p.HideProduct <> ‘Y’)
AND (pe.ProductPrice > 0)
ORDER BY p.ProductCode

Database Overload

May 19th, 2009 Comments off

Dear everyone,

I’m having right now a problem with my hosting site, the problem is that my database is making overload in the server because of some code and I should delete these codes,

but the problem I don’t now what is the codes are coding for and where I can find them,

so what I want is someone tell me what these code are and help me by deleting them,

the codes:
queries that caused overload, they are as follows for Phantom_forum database:

-&amp;gt;Query summary
Time: 13% (1393 sec) Amount: 13% (109 queries) Rows Examined/Sent: 73923 / 109 Avg. Query Exec/Lock Time: 12 / 0 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT COUNT(*) AS posts FROM post AS post WHERE threadid = 1826 AND visible = 1 AND dateline &amp;lt;= 1229550419;
|id rows Extra
|1 393 Using where
|__________________
-&amp;gt;Query summary
Time: 12% (1210 sec) Amount: 9% (75 queries) Rows Examined/Sent: 107226 / 727 Avg. Query Exec/Lock Time: 16 / 0 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT post.postid FROM post AS post WHERE post.threadid = 2139 AND post.visible = 1 ORDER BY post.dateline LIMIT 360, 10;
|id rows Extra
|1 571 Using where; Using filesort
|__________________
-&amp;gt;Query summary
Time: 5% (588 sec) Amount: 6% (50 queries) Rows Examined/Sent: 670 / 670 Avg. Query Exec/Lock Time: 11 / 4 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT * FROM datastore WHERE title IN (”,’options’,'bitfields’,'attachmentcache’,'forumcache’,'usergroupcache’,'stylecache’,'languagecache’,'products’,'pluginlist’,'cron’,'profilefield’,'loadcache’,'noticecache’,'smiliecache’,'bbcodecache’,'banemail’,'noavatarperms’);
|id rows Extra
|1 18 Using where
|__________________
-&amp;gt;Query summary
Time: 4% (436 sec) Amount: 4% (35 queries) Rows Examined/Sent: 12228 / 3897 Avg. Query Exec/Lock Time: 12 / 5 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT userid, lastactivity, options, username, user.usergroupid, displaygroupid, groupa.opentag as opentaga, groupa.closetag as closetaga, groupb.opentag as opentagb, groupb.closetag as closetagb FROM user as user LEFT JOIN usergroup as groupa ON(user.usergroupid = groupa.usergroupid) LEFT JOIN usergroup as groupb ON(user.displaygroupid = groupb.usergroupid) WHERE lastactivity &amp;gt; 1242286910 ORDER BY username;
|id rows Extra
|1 214 Using where; Using filesort
|1 1
|1 1
|__________________
-&amp;gt;Query summary
Time: 3% (401 sec) Amount: 3% (30 queries) Rows Examined/Sent: 29540 / 277 Avg. Query Exec/Lock Time: 13 / 0 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT SQL_CALC_FOUND_ROWS visitormessage.*, user.*, visitormessage.ipaddress AS messageipaddress ,avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb, filedata_thumb, NOT ISNULL(customavatar.userid) AS hascustom FROM visitormessage AS visitormessage LEFT JOIN user AS user ON (visitormessage.postuserid = user.userid) LEFT JOIN avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN customavatar AS cust … [too long]
|id rows Extra
|1 232 Using where
|1 1
|1 1
|1 1
|__________________
-&amp;gt;Query summary
Time: 3% (353 sec) Amount: 3% (28 queries) Rows Examined/Sent: 240226 / 704 Avg. Query Exec/Lock Time: 12 / 0 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT user.*,usertextfield.*,userfield.*, user.userid, options, IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid ,avatar.avatarpath,NOT ISNULL(customavatar.userid) AS hascustomavatar,customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight , IF((options &amp; 512 AND user.userid &amp;lt;&amp;gt; 0), 0, lastactivity) AS lastvisittime , user.xperience, user.xperience_level FROM user AS user LEFT JOIN usertextfield AS usertextfield ON(usertextfield.userid=user.userid) LEFT JOIN userfield AS userfield ON(userfield.userid=user.userid) LEFT JOIN av … [too long]
|id rows Extra
|1 3593 Using where; Using filesort
|1 1
|1 1
|1 1
|1 1
|__________________
-&amp;gt;Query summary
Time: 2% (294 sec) Amount: 3% (26 queries) Rows Examined/Sent: 42217 / 26 Avg. Query Exec/Lock Time: 11 / 0 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT COUNT(*) AS count_posts FROM post AS p INNER JOIN thread as t ON p.threadid=t.threadid WHERE p.visible=1 AND p.userid=2576;
|id rows Extra
|1 509 Using where
|1 1 Using index
|__________________
-&amp;gt;Query summary
Time: 2% (220 sec) Amount: 3% (25 queries) Rows Examined/Sent: 1638 / 210 Avg. Query Exec/Lock Time: 8 / 1 sec.
Used databases: [Phantom_forum]
Query example: use Phantom_forum; SELECT post.*, post.username AS postusername, post.ipaddress AS ip, IF(post.visible = 2, 1, 0) AS isdeleted, user.*, userfield.*, usertextfield.*, icon.title as icontitle, icon.iconpath, avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight, editlog.userid AS edit_userid, editlog.username AS edit_username, editlog.dateline AS edit_dateline, editlog.reason AS edit_reason, editlog.hashistory, postparsed.pagetext_html, postparsed.hasimages, sigparsed.signatureparsed, sigparsed.hasimages AS sighasimag … [too long]
|id rows Extra
|1 11 Using where; Using filesort
|1 1
|1 1
|1 1
|1 1
|1 1
|1 1
|1 1
|1 1
|1 1
|1 1
|__________________

I want a really fast solving for this problem,

Note: My database contain VB forum &amp; Joomla 1.

Best Regard,
Sarab

Categories: Joomla, MySQL, PHP Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Bear