SELECT TOP 20 a.*
FROM
(
SELECT ROW_NUMBER() OVER( ORDER BY a.Title ASC, a.Open_Date_Int DESC, a.CategoryID DESC )
AS RowNumber,
a.CategoryID, a.Title, a.Open_Date, a.PictureID, a.PSrpBaht, a.P2, a.P7, a.ShipUnit, a.BoomRate,
b.P_TYPE, b.P_TABLE,
dis.DistributorNameWeb , dis.Import
FROM PRODUCT_HEAD a
LEFT JOIN PRODUCT_TYPE AS b ON a.P_ID = b.P_ID
LEFT JOIN DISTRIBUTOR AS dis ON a.DistributorID = dis.DistributorID
LEFT JOIN VIEW_TOTALSTOCKWEB AS st WITH (NOLOCK) ON a.CategoryID = st.CATEGORYID2
WHERE a.Status = 1 AND a.WebStatus = 1 AND a.SaleStatus = 1
AND a.CategoryID IN(11280,28082,28598,38969,43044,47120,60107,60299,60528,61694,67320,67350,82539,82541,84059,84080,87688,95752,95760,99863,99885,101199,101287,101514,105619,105622,105714,107769,111684,115899,116497,116726,117326,126429,133512,137298,147670,151483,155430,155431,155432,155439,155507,155697,156681,157340,160119,174543,176327,180860,180861,181682,194394,194395,196489,196499,198873,200461,205118,207153,214297,216498,217481,218180,218182,218198,226901,230978,232189,234203,234273,234344,235128,236442,237379,237380,237743,241211,250354,250384,252187,253191,263199,269697,269726,273849,274874,274922,275782,279014,279017,279280,279284,279928,279937,280871,280920,281363,281829,285777,285916,286758,287402,287407,288071,288208,288222,288961,288969,288972,289353,289354,290472,290683,290685,290689,291370,291384,291540,292598,292746,293035,293637,298409,320251,322268,322311,322312,322315,322345,322562,322563,322578,322592,322598,322708,329731,336649,336860,336889,339547,339715,355344,367710,367751,367786,387968,457354,461168,461169,461180,461266,515405,516567,516606,516607,516725,516727,516728,516729,516731,524255,524256,527103,530466,554512,556880,558485,558498,560962,560971,560975,566047,566051,568362,573914,573975,574013,574015,574062,574067,574073,574123,574201,574205,574208,574210,574211,576465,579038,579578,579584,579586,579588,588379,588380,588381,588382,588383,598497,600361,600571,602505,602612,602614,605332,605337,608572,619462,625029,665533,669602,669752,669767,669768,669804,684448,687706,687709,687712,687732,687740,687741,687750,687799,687836,687842,687857,687859,687863,687873,689508,691109,691111,691117,692276,692283,692314,692315,692359,692361,692453,692454,692456,692460,692461,692462,694519,694539,694542,694552,694560,694561,694572,694574,694578,694585,694586,694594,696222,696228,697847,701473,701486,701488,701543,701568,704321,704427,711889,714990,715000,717977,720370,720372,726978,726980,726981,738925,738929,741350,741415,741422,741526,743657,746930,746931,746933,746934,749097,749109,750833,750838,750915,750985,753863,753865,753867,753868,753869,754074,760317,760332,761560,761601,765801,775832,775882,775883,775885,775962,778817,778849,778906,781657,781658,781734,783987,784057,784064,784127,786874,786941,786943,786944,786947,786950,786953,786966,786988,786989,789327,789354,789500,794993,794994,794995,795007,795017,795019,801730,809747,809748,809752,809754,811149,812887,813900,822404,822484,822489,822493,822496,822497,822498,822501,822502,830033,830035,830185,830295,830345,831460,833446,833452,845491,845524,849020,849021,851755,851760,851761,851762,851820,851821,851824,851827,853630,853631,853637,853638,853639,853673,857298,858777,858787,859903,859904,859905,859937,859939,859943,859944,859947,859949,859950,862673,868940,868942,868948,868953,868954,868955,868965,876049,876053,880947,883074,883077,883181,883199,883200,883205,883206,887830,887833,887841,887847,887987,887989,894044,894045,894058,897636,899647,905863,905870,907875,907877,907878,907879,907882,907887,907889,909934,914388,916604,916661,916743,916745,917025,917036,920178,920179,920186,925016,927420,927456,927458,929229,929302,935967,935969,937936,937937,947743,948006,948013,948020,948024,955456,955458,955527,955538,955566,955567,955570,956935,956937,956940,956942,956946,961262,963452,963456,963458,963459,963467,963468,965058,965061,993831,993833,993837,993838,1001810,1001931,1001934,1006772,1006774,1006775,1006776,1006777,1006778,1006779,1006783,1006795,1006796,1009138,1009149,1009157,1013279,1015553,1015559,1015562,1015563,1015564,1015565,1015566,1015571,1015573,1015577,1015580,1024889,1024894,1024903,1024909,1024910,1025125,1025127,1025129,1025137,1025144,1025146,1030844,1037008,1037054,1037142,1037154,1042335,1042340,1042341,1042342,1042343,1042345,1042462,1042521,1046372,1049756,1049904,1049905,1049952,1049954,1049955,1049956,1049957,1049962,1049963,1059450,1060566,1065797,1073518,1073520,1076477,1084908,1084995,1091046,1091048,1091049,1091063,1091084,1091086,1091103,1091340,1091346,1091347,1091417,1097751,1097800,1097802,1101398,1101593,1101594,1101598,1101600,1101603,1107352,1107374,1109548,1109551,1109647,1109648,1109692,1112770,1112857,1123346,1123439,1123441,1123520,1128978,1132955,1132971,1132973,1132975,1138601,1140837,1140848,1144935,1144939,1144943,1144944,1144947,1144948,1144950,1144954,1144967,1144972,1144977,1144980,1145041,1146658,1146660,1146661,1146665,1146675,1146677,1146678,1146682,1149118,1149131,1149188,1151309,1151356,1151372,1151382,1151496,1151498,1151499,1155301,1155303,1158494,1158546,1158564,1158568,1160490,1160518,1160593,1163567,1165355,1165361,1165462,1165464,1165465,1165466,1165468,1172582,1172584,1172585,1172586,1178246,1178248,1178251,1178259,1178283,1191187,1191189,1191190,1191191,1191228,1193573,1193574,1193577,1193580,1193587,1193616,1195441,1197410,1197461,1197462,1197558,1197589,1197591,1197705,1197710,1197712,1197724,1205904,1205908,1205912,1205922,1205925,1205927,1205928,1205933,1205940,1205942,1205944,1205945,1205946,1205949,1205950,1205951,1205952,1205954,1205955,1205957,1205959,1208343,1208402,1208405,1211776,1211890,1214325,1214332,1214374,1219298,1219303,1219314,1225461,1225551,1227246,1227251,1227258,1227281,1246499,1246508,1246515,1270041,1270042,1278407,1282076,1282078,1282100,1282103,1284096,1284122,1289458,1289460,1292709,1292744,1298985,1298988,1298989,1299028,1299119,1302122,1302139,1302155,1302164,1304989,1310155,1310176,1310179,1310217,1310218,1310219,1315330,1315338,1315368,1315422,1315435,1315444,1315450,1315489,1317399,1317456,1317475,1317503,1317504,1317509,1317510,1317511,1317512,1317513,1317514,1317515,1317516,1317517,1317518,1317519,1317520,1317521,1317522,1317523,1317524,1317525,1317526,1317527,1317528,1317529,1317530,1317531,1317532,1317533,1317534,1317535,1317536,1317537,1317538,1317539,1317540,1317541,1317542,1317543,1317544,1317545,1319968,1319981,1319983,1319984,1319988,1319989,1319991,1319992,1319994,1319995,1319996,1319997,1322558,1324586,1324589,1331798,1331800,1331821,1331825,1334957,1334958,1337249,1337251,1342248,1342502,1342505,1342516,1342520,1342526,1354844,1354959,1354960,1356859,1356860,1356861,1356864,1359301,1359305,1360517,1360532,1360534,1360552,1360559,1362090,1362091,1364215,1369333,1369345,1369375,1369377,1369378,1371026,1373889,1373890,1373891,1373893,1373894,1375278,1375279,1377099,1377102,1377104,1377108,1377110,1377111,1377114,1379045,1379058,1380708,1380709,1380711,1380718,1380719,1380723,1382630,1384466,1384468,1384469,1384472,1384474,1384475,1384479,1385595,1390124,1390126,1392135,1392140,1392143,1392158,1392160,1392238,1392245,1392264,1392266,1397091,1397093,1399799,1399803,1399843,1399864,1399899,1399902,1399904,1399905,1399906,1409542,1409544,1409545,1409546,1409550,1409551,1409553,1409554,1409555,1409556,1409557,1409565,1409570,1410665,1416949,1416956,1419002,1419003,1419005,1419006,1419007,1419008,1419009,1419011,1419012,1419019,1419020,1419022,1419023,1419024,1419042,1419043,1419071,1419088,1419090,1421088,1421089,1421090,1421092,1421093,1421094,1421096,1421097,1421098,1427129,1427170,1427172,1429272,1431807,1431828,1431868,1431869,1431896,1435019,1435130,1435133,1435134,1435138,1435154,1435155,1435156,1435157,1435158,1435159,1435162,1435163,1435164,1435165,1435166,1435167,1435168,1435170,1435171,1435172,1435173,1435174,1436455,1437780,1439053,1439056,1439058,1439059,1439073,1439078,1439097,1439104,1440407,1440408,1440409,1440448,1440449,1440450,1440451,1440452,1440454,1440457,1440458,1440460,1441518,1441520,1444457,1444458,1444461,1444462,1444463,1444465,1445489,1445490,1454663,1454668,1454669,1454671,1454672,1454673,1454674,1459443,1459444,1459480,1459483,1459488,1459493,1459497,1463305,1463306,1463307,1463319,1463321,1463323,1466764,1466765,1469181,1469182,1469186,1471543,1472342,1472343,1472345,1472349,1472350,1473153,1473155,1475484,1476615,1476616,1476622,1476625,1477529,1477530,1477531,1479508,1479511,1479512,1479514,1479517,1479559,1480336,1480338,1480382,1480383,1480384,1480385,1481179,1481229,1483347,1483348,1483351,1483352,1483354,1483357,1484102,1484745,1484747,1484831,1484832,1484901,1484902,1484903,1484905,1484906,1488571,1490443,1490444,1490445,1490447,1490448,1490449,1490450,1490464,1490468,1490469,1490470,1490471,1490473,1490474,1490475,1490476,1490477,1490478,1490479,1490480,1491181,1491184,1491185,1492764,1494918,1494921,1494923,1494952,1494965,1495861,1495862,1497123,1497127,1497128,1497135,1497136,1497137,1497138,1497139,1497141,1501952,1501969,1501970,1501976,1503227,1503230,1503250,1503253,1503257,1503265,1503267,1503269,1503272,1503274,1503278,1503280,1503281,1504513,1505568,1507716,1507717,1507718,1507720,1507723,1507724,1507726,1507736,1507749,1511420,1511448,1511450,1511451,1511452,1511453,1511454,1511455,1511456,1511457,1511458,1511459,1511460,1513826,1513827,1513828,1514630,1514636,1514898,1514903,1514905,1514910,1514926,1514930,1515962,1515969,1515973,1517360,1517365,1517367,1517377,1518600,1518629,1519907,1519910,1519915,1543425,1543430,1544655,1544660,1544663,1545871,1545872,1546770,1546772,1546775,1546779,1546786,1546793,1548645,1552351,1553021,1553022,1553023,1553026,1553212,1553255,1553256,1553257,1553258,1553259,1553260,1553261,1553299,1553383,1553384,1562840,1562860,1563915,1563916,1563918,1563919,1564768,1564776,1566901,1566903,1568911,1570131,1570132,1573450,1573455,1573465,1573466,1573474,1573477,1573479,1573483,1575258,1575259,1577134,1577135,1577138,1577140,1577148,1577152,1577162,1577211,1579477,1579479,1580453,1580454,1580455,1580456,1580457,1584398,1585400,1585402,1585405,1585414,1585434,1585435,1585462,1585465,1585696,1585697,1585698,1585699,1585795,1585797,1587964,1587965,1587966,1587969,1593772,1593773,1593777,1593781,1594842,1594847,1594849,1595930,1595932,1595933,1595975,1596940,1597965,1597967,1599091,1599093,1599094,1599096,1599098,1599101,1599103,1599122,1599123,1599124,1599129,1599130,1599131,1599132,1599133,1599134,1600335,1600337,1600613,1600697,1600702,1604820,1604821,1604825,1604826,1604827,1604828,1610626,1610628,1612147,1612148,1612149,1614566,1617520,1617521,1619165,1622974,1622977,1622978,1622979,1624506,1624509,1624532,1624533,1636301,1636307,1636309,1636311,1636324,1636328,1636331,1639074,1639077,1639080,1639084,1639090,1639091,1639092,1639093,1641368,1642208,1642209,1642211,1642214,1642215,1642216,1642217,1642223,1642232,1642233,1642234,1642235,1643464,1645577,1646428,1649111,1649112,1649753,1649754,1650394,1650395,1650396,1650397,1650398,1650399,1651767,1652438,1652439,1652440,1653361,1654893,1654894,1654922,1654923,1654924,1654925,1654927,1654929,1655021,1656388,1659907,1659908,1659909,1659932,1659933,1659934,1659935,1659936,1659937,1659938,1659939,1664011,1664012,1664013,1664016,1664784,1667701,1667702,1667705,1667723,1667724,1673173,1673174,1691956,1691960,1691961,1691962,1691963,1694279,1694280,1694281,1694282,1694283,1696963,1696964,1696965,1701589,1701590,1701591,1701592,1707118,1709888,1710695,1778820,1490454,1501963,1494917)
AND st.TOTALSTOCK > '0' AND st.TOTALSTOCK > ( SELECT isnull(SUM(QTYB), 0) AS OQ FROM SO WITH (NOLOCK) WHERE (Status = 1 OR Status = 6) AND PersonID > 50 AND CategoryID = a.CategoryID )
) AS a
WHERE RowNumber BETWEEN 1 AND 20
Product | BoomerangShop.com - Thailand Online Blu-Ray, DVD, CD Store