[英]MS SQL Conversion failed when converting the varchar value to data type int and JOIN two Tables
I get an error saying: "Conversion failed when converting the varchar to data type int " when I try to run the code below, but I already converted the ASSIGNED_ID
to int in php ? 当我尝试运行以下代码时,我收到一条错误消息: “将varchar转换为int数据类型时转换失败” ,但是我已经在php中将
ASSIGNED_ID
转换为int了?
The $row["ID"]
number is small its 2 so there are no , or anything like that, I even added a replace code to remove any spaces, but it still doesn't work. $row["ID"]
数字小于2,所以没有或类似的东西,我什至添加了替换代码来删除任何空格,但仍然无法正常工作。 Also both tables have the same ID (data type: int) 另外,两个表具有相同的ID(数据类型:int)
I would also like to know how I can join the two tables: T_ASSIGNED
and T_EQ
using their ID (int)
they both have it and it always matches 我还想知道如何连接两个表:
T_ASSIGNED
和T_EQ
使用它们的ID (int)
它们都具有它并且总是匹配
// SEND A SELECT QUERY TO MSSQL
$query = mssql_query('SELECT ID FROM [TestT].[dbo].[T_ASSIGNED] WHERE [A_T_N]=\'$contact_lastname\'');
$row = mssql_fetch_array($query);
if (strlen($row["ID"])<>0) {
// REMOVE ANY SPACES AND CONVERT ID TO INT
$ASSIGNED_ID = intval(str_replace(" ", "", $row["ID"]));
}else{
// IF NO ID IS FOUND MAKE ID BE ZERO
$ASSIGNED_ID =intval('0');
};
// FREE THE QUERY RESULT
mssql_free_result($query);
// ECHO THE ID
ECHO("TEST ID: ".$ASSIGNED_ID);
// GET THE T NUMBER IN THE T_EQ LOCATION
$query = mssql_query('SELECT EQ_T_N FROM [TestT].[dbo].[T_EQ] WHERE [ID]=\'$ASSIGNED_ID\'');
$row = mssql_fetch_array($query);
// ECHO THE EQ_T_N
echo(">".$row["EQ_T_N"]."<");
// FREE THE QUERY RESULT
mssql_free_result($query);
THANKS FOR ANY HELP. 谢谢你的帮助。
use this 用这个
mssql_query('SELECT EQ_T_N FROM [TestT].[dbo].[T_EQ] WHERE [ID]="' . $ASSIGNED_ID .'"');
by using single quotes, you're using the text of $ASSIGNED_ID
, not the value of that variable 通过使用单引号,您使用的是
$ASSIGNED_ID
的文本,而不是该变量的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.