I have two different SQL Tables, both of them have an uniqueidentifier field called ID.
On my website, im calling a query to store into a variable the uniqueidentifier field from the table A.
$query = "SELECT ID FROM [dbo].[TableA] WHERE Name='{$name}'";
$result = sqlsrv_query($conn, $query);
while ($row = sqlsrv_fetch_array($result)){
$ID= $row['ID'];
}
Then, after storing this unique identifier into $ID, im inserting it into the TableB.
$query = "INSERT INTO [dbo].TableB(ID) values ('{$ID}')";
$result = sqlsrv_query($conn, $query);
This will not work, showing the following error on sqlsrv_errors()
Syntax error, permission violation or other non-specific error.
The query works properly when we change $ID for newid(), but im looking towards inserting my own value rather than generating a new one.
The $ID echo shows this: D52A7C05-0399-4C82-8662-0F5731B4062C, which is exactly the same value that is currently stored into the TableA id.
Maybe when I am storing the uniqueidentifier on $ID its being converted into string, therefore not being a correct value to be inserted as uniqueidentifier?
FIXED: Found out that I had a very small syntax error on the query. Used var_dump($query);
to figure it. Thanks @ADyson.