Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7034689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:12:59+00:00 2026-05-28T01:12:59+00:00

I have this sql query which runs fine when I execute it in MSSQL

  • 0

I have this sql query which runs fine when I execute it in MSSQL Management Studio, but when I try to execute it in PHP it gives me no output.

Any suggestions?

//gets ID

 $atz_id = $_GET['atz_id'];

//SQL query

 $q2 = "
 declare @atzID int             set @atzID=$atz_id; 


 if object_id('tempdb..#vesture1') is not null drop table #vesture1
 select distinct
 atz_id,
 datums s_dat,
 cast(NULL as datetime) b_dat,
 tips
 into #vesture1
 from guna..erg2_atzistas_o o
 where
 darbiba=1
 and atz_id=@atzID


  update #vesture1 set b_dat=(select top 1 datums from guna..erg2_atzistas_o where atz_id=#vesture1.atz_id and darbiba=0 and tips=#vesture1.tips and datums > #vesture1.s_dat order by datums asc)


 if object_id('tempdb..#vesture2') is not null drop table #vesture2
 select distinct
 atz_id,
 convert(varchar, s_dat, 104) s_dat,
 convert(varchar, b_dat, 104) b_dat,
 substring((select ', '+tips from #vesture1 where atz_id=v.atz_id and s_dat=v.s_dat and isnull(b_dat,0)=isnull(v.b_dat,0) order by tips for xml path('')), 3, 3000) 'sugas'
into #vesture2
from #vesture1 v

select * from #vesture2 order by s_dat, b_dat
";

//runs query

$res2=mssql_query($q2);

//checks if there is some output (there is not – other queries outputs 0 or number of rows, this one dont)

$num_rows2 = mssql_num_rows($res2);


 echo $num_rows2;

//outputs data

echo "<table border='1' class='saraksts_table' width='100%' cellspacing='0'>
<tr class='saraksts_header'>
<th><center><font size='1.2px'>info</font></center></th>
<th><center><font size='1.2px'>xxxx</font></center></th>
<th><center><font size='1.2px'>axxa</font></center></th>
<th><center><font size='1.2px'>SAAAa</font></center></th>
</tr>";

while($row2 = mssql_fetch_array($res2))
{
echo "<tr style=background-color:white;>";
echo "<td>" . $row2['atz_id'] . "</td>";
echo "<td>" . $row2['s_dat'] . "</td>";
echo "<td>" . $row2['b_dat'] . "</td>";
echo "<td>" . $row2['sugas'] . "</td>";
echo "</tr>";
}
echo "</table>";

Updated
Error messages :

   PHP Warning:  mssql_query(): message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (severity 16) in /home/info/info_pub/sql_vesture.php on line 108
   PHP Warning:  mssql_query(): General SQL Server error: Check messages from the SQL Server (severity 16) in /home/info/info_pub/sql_vesture.php on line 108
   PHP Warning:  mssql_num_rows() expects parameter 1 to be resource, boolean given in /home/info/info_pub/sql_vesture.php on line 112
   PHP Warning:  mssql_fetch_array() expects parameter 1 to be resource, boolean given in /home/info/info_pub/sql_vesture.php on line 167
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:12:59+00:00Added an answer on May 28, 2026 at 1:12 am

    i had to convert data type – > http://msdn.microsoft.com/en-us/library/aa226054%28v=sql.80%29.aspx

    updated select – took a while to figure it out

               select atz_id, s_dat, b_dat, **cast(sugas as varchar)as sugas** from #vesture2 order by s_dat, b_dat;
    

    thanks all for help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have this SQL query which is valid but always times out:
I have report1.jrxml which have simple SQL query with no parameters and runs fine
I have the following query which runs fine on all of my sql server
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
i have the following SQL Query which runs on SQL Server CE 4 SELECT
I have VBA code to run a query in SQL-Server 2008. It runs fine
I have the following script which runs fine but I think a) it is
This one has me rather confused. I've written a query which runs fine from
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have this SQL query select case when AllowanceId is null then 2 else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.