Question : PHP & MSSQL - Problem with basic query not working...

I have a problem while trying to run a SQL query within PHP - i'm sure its worked previously but i just cant get it to go anymore..!

What i'm trying to do is to copy one table to another, with the results filtered - but for testing purposes only, i've reduced the code down to simply copy one table to another, but it still isnt working!

It seems to do something though - before running this code i have been manually dropping the table, after the code has then been run the table 'SugJobs2' DOES exist, but with no data.

The table 'SugJobs' contains 6592 rows of data (so i'm not copying from an empty table!)

If i run the same query within Management Studio it runs without any problems and the data is in the new table.

Anyone have any ideas where i am going wrong?

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
<?php

// MSSQL Server
$SQLSERV = "SERVERNAME";
// MSSQL Username
$SQLUSER = "USERNAME";
// MSSQL Password
$SQLPASS = "PASSWORD";

$link = mssql_connect($SQLSERV, $SQLUSER, $SQLPASS);

if (!$link || !mssql_select_db('CoA', $link)) {
    die('Unable to connect or select database!');
}

$query1 = mssql_query("
SELECT * INTO SugJobs2
	FROM SugJobs
");

$query1;

?>

Answer : PHP & MSSQL - Problem with basic query not working...

I don't know what you mean by "work" but do you mean

SELECT A.* INTO SugJobs2
      FROM (
SELECT      B.*
      FROM      MiniSugJobs AS B
LEFT OUTER JOIN ProdWC AS C
      ON      B.StockCode=C.StockCode  AND RTRIM(LTRIM(C.WorkCentres)) IN('WC1', 'WC2', 'WC3')
WHERE
      B.JobStartDate < '18-AUG-2010'
) AS A

But you might as well drop the left join since it plays no part in select b.*
Otherwise, if you are filtering on C, you might want to change the LEFT to INNER join.
All it means is that there really are no matches for [C.WorkCentres IN('WC1', 'WC2', 'WC3')]
Random Solutions  
 
programming4us programming4us