Jump to content

Gamic

Members
  • Posts

    101
  • Joined

  • Last visited

    Never

Everything posted by Gamic

  1. What you really want is something that looks like this: update a set approval_date = b.date from <tableName> a join <tableName> b on a.id = b.parentid where a.approval_date <= '1 Jan 1970' --rest of where clause
  2. I would look at adding something like the below to your output (commented out lines). This will only not display the company name if the current company being echoed is the same as the last. <?php echo " <a href=\"#\"><img src=\"/images/sm/" . $img . ".gif\" class=\"hotel-thumb\" alt=\"New York Limo Deals\"></a>"; //if ($lastCompany != $company) echo "<p class=\"name\">" . $company . " </p>"; echo "<p class=\"hotel\">Save Up to " . $percentage . " % for your next " . $type . " Service</p>"; echo "<p></p>"; echo "<br class=\"clear-right\"> </div></div></div>"; //$lastCompany = $company; } ?>
  3. where is a condition. You don't require a condition on an insert, (unless, perhaps, you are inserting from a select query). something likes this should be more than good enough: <?php $query = "insert into users(<fieldlist>) values (0, '".$filename."')"; ?> You may also need to think about what you are trying to do. Are you trying to create a new users, or are you trying to update an old user with a new profile picture (or something completely different yet again).
  4. Those numbers have gone for a walk . But yea, just goes to show how silly one little typo can be. create table #test( n int ); insert into #test(n) values (1); insert into #test(n) values (2); insert into #test(n) values (3); select distinct convert(char(1),t1.n) + convert(char(1), t2.n) + convert(char(1), t3.n) as 'output' -- typo last time was t2.n being used twice... silly me! from #test t1 cross join #test t2 cross join #test t3 order by 1 asc ; drop table #test; And this now produces the much better output: output ------ 111 112 113 121 122 123 //Here's one! 131 132 //Ah, This one was missing too! 133 211 212 213 //And you! 221 222 223 231 232 233 311 312 313 321 322 323 331 332 333 //Only half evil!
  5. Just for fun: create table #test( n int ); insert into #test(n) values (1); insert into #test(n) values (2); insert into #test(n) values (3); select distinct convert(char(1),t1.n) + convert(char(1), t2.n) + convert(char(2), t2.n) as 'output' from #test t1 cross join #test t2 cross join #test t3 order by 1 asc ; Result: output ------ 111 122 133 211 222 233 311 322 333 (9 row(s) affected) Seemed a lot easier than driving a nail into a wall - but will become a lot more annoying when you need to add extra numbers
  6. The reason it doesn't work is because ONPO and POCOST are not columns in Purchase_Order_Dtail. Renaming the columns only changes the names for the output, and not for the table itself. (For that you would need to alter the table). Both of the examples below should work: In an inline view: SELECT *, ONPO * POCOST as EXT FROM ( SELECT PURCHASE_ORDER_DTAIL.WHSE, PURCHASE_ORDER_DTAIL.CODE, PURCHASE_ORDER_DTAIL.POD_DESCRIPTION, PURCHASE_ORDER_DTAIL.BVORDQTY, PURCHASE_ORDER_DTAIL.BVTODATEQTY, PURCHASE_ORDER_DTAIL.BVUNITPRICE AS 'POCOST', PURCHASE_ORDER_DTAIL.BVORDQTY-PURCHASE_ORDER_DTAIL.BVTODATEQTY AS 'ONPO', CASE PURCHASE_ORDER_DTAIL.WHSE WHEN 'QT' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'U1' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'VM' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'GR' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'AT' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'AC' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'C1' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'RE' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'RQ' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'QM' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'FG' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'X1' THEN 'X_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) END AS 'LOOKUP' FROM PURCHASE_ORDER_DTAIL WHERE (PURCHASE_ORDER_DTAIL.BVORDQTY>0) )t Or just using the column names: SELECT PURCHASE_ORDER_DTAIL.WHSE, PURCHASE_ORDER_DTAIL.CODE, PURCHASE_ORDER_DTAIL.POD_DESCRIPTION, PURCHASE_ORDER_DTAIL.BVORDQTY, PURCHASE_ORDER_DTAIL.BVTODATEQTY, PURCHASE_ORDER_DTAIL.BVUNITPRICE AS 'POCOST', PURCHASE_ORDER_DTAIL.BVORDQTY-PURCHASE_ORDER_DTAIL.BVTODATEQTY AS 'ONPO', PURCHASE_ORDER_DTAIL.BVORDQTY-PURCHASE_ORDER_DTAIL.BVTODATEQTY * PURCHASE_ORDER_DTAIL.BVUNITPRICE as 'EXT' CASE PURCHASE_ORDER_DTAIL.WHSE WHEN 'QT' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'U1' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'VM' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'GR' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'AT' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'AC' THEN 'U_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'C1' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'RE' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'RQ' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'QM' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'FG' THEN 'C_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) WHEN 'X1' THEN 'X_'+RTRIM(PURCHASE_ORDER_DTAIL.CODE) END AS 'LOOKUP' FROM PURCHASE_ORDER_DTAIL WHERE (PURCHASE_ORDER_DTAIL.BVORDQTY>0) And there are, of course, many other ways to do this.
  7. Just for completeness: Sometimes you will not be able to truncate the table because there are foreign key constraints. In these cases you could either drop and create the table, or delete and reset the seed: DELETE FROM tableName; DBCC CHECKIDENT('tableName', RESEED, 0); [/Code]
  8. Did you mean something, more along the lines of, this? SELECT I_USER FROM RATE_PICUTRES T1 WHERE I_STATUS <> 2 EXCEPT --where the user id is not also in SELECT I_USER FROM RATE_PICUTRES T1 WHERE I_STATUS = 2
  9. Create Procedure Create Index Try to do this yourself and we may be inclined to help.
  10. Make sure that the user you are using to connect to SQL Server has the correct default schema for his/her/its connection to the database. ALTER USER userName WITH DEFAULT_SCHEMA = sf Alter User Syntax
  11. I think this is the query that you want: select ap.name, --From $sql1 ap.panelID, --From $sql1 e.devID, --From $sql2 and potentially redundent as you only used this data input into the third query. e.inputdevid, --From $sql3 e.eventid, --From $sql3 from accessPane ap join events e on ap.panelID = e.Machine where ap.paneltype in (14,19,59,63,10) and e.eventID in (8,10,2,431,18,4,6,20,5,7,76) and e.eventType = 4 and e.event_time_utc >= DateAdd(day,-1,getDate()) --This will be exactly 24 hours ago. You may need work out if you want to start at the beginning of the day group by ap.name, ap.panelID, e.devID, e.inputDevID, e.eventID
  12. You shouldn't need to have php looping through queries to prepare new queries in this way. Why not try and write one query that will give you the information you need? select el.PanelID, el.DeviceID, el.InputDevID, max(events.Event_Time_UTC) as time from evtalmlink el join events on el.panelid = " . " + convert(nvarchar(20),machine.panelid) + " . " where eventid = and eventype = 4 --(etc) group by el.panelid, el.deviceid, el.inputdevid [/Code] It's not perfect (as I am not sure entirely what you are trying to do).
  13. Something like this may get the results that you want: select allRuns.* from( select time, distence, date from location )allRuns join( select min(time) as time, distence from running group by distance ) minDistence on allRuns.time = minDistence.time and allRuns.distence = minDistence.distence Although I'm sure there is a better way, I just can't think of it right now.
  14. In the trigger you would want something like this: declare @deletedUserName as <someType> select @deletedUserName = userNameField from deleted
  15. <?php $SQL = " select * from( select my_state, count(*) as countOfUse from t_locations group by my_state )tmp order by tmp.countOfUse desc"; ?> This query tells you how many times a value of my_state appears in t_locations. To get the most commonly paid price for a state you would do something similar. selet * from( select my_price, count(*) as countOfUse from t_locations where my_state = 65 group by my_price )tmp order by tmp.countOfUse desc
  16. select * from( select numberField, count(*) as countOfUse from table group by number )tmp order by tmp.countOfUse desc
  17. SELECT a.siteID 'ID', a.siteDomain 'Site', COUNT(b.*) 'New Members' FROM sites a LEFT OUTER JOIN users b ON a.siteID=b.siteID WHERE (b.userDateRegistered between '1231513284' and '1231553482') or b.userDateRegistered is null GROUP BY a.siteID
  18. You don't include the cars table. You instead include rate and ratings. SELECT AVG(rate.rating), cars.name_, cars.engine, cars.wheels FROM rate inner join cars on rate.name_ = cars.name_ GROUP BY cars.name_, cars.engine, cars.wheels ORDER BY AVG(rate.rating)
  19. is ['playertarget'] the name of the field in the table? <?php $br = "<br />\n"; foreach ($target as $key =>$value){ echo $key.$br; } ?>
  20. You could do something like this: insert into tablea(a,b,c) select a, b, c from ( select '1' as a, '2' as b, '3' as c, 'someID' as id, 'somepassword' as password ) as tmp inner join tableb on tableb.id = tmp.id and tableb.password = tmp.password
  21. What does selecting * from the table do with the same where condition?
  22. update pollcomments set username = u.username from pollcomments p inner join users u on p.userid = u.userid
  23. SELECT `submittedby`, COUNT(*) AS postCount FROM `sites` WHERE `confirmed` = '1' GROUP BY `submittedby` HAVING postCount BETWEEN 90 AND 1110 (90<110<1110). You only need one condition for this particular count. For conditions that don't completly overlap though you would do something like this: SELECT `submittedby`, COUNT(*) AS postCount FROM `sites` WHERE `confirmed` = '1' GROUP BY `submittedby` HAVING (postCount BETWEEN 90 AND 1110) OR (postCount between 2000 AND 2099) [code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.