UPDATE: the bio may contain apostrophes (see updated example)
I have an SQL query that has a value which spans multiple lines and it causes the query to fail:
UPDATE User SET UserId=12345, Name="J Doe", Location="USA", Bio="I'm a bio that has an apostrophe, and I'm spanning multiple lines!" WHERE UserId=12345
In C# you can put an @
before the string Bio=@"..."
in order to allow it to span multiple lines, but I'm not sure how the same thing can be achieved with SQL queries. How do you get a string to span multiple lines without having to do things like manually concatenating the strings:
Bio="I'm a" +" bio that has an apostrophe, and I'm" +" spanning multiple lines!"
Multi-line comments start with /* and end with */ . Any text between /* and */ will be ignored.
The STRING_SPLIT(string, separator) function in SQL Server splits the string in the first argument by the separator in the second argument. To split a sentence into words, specify the sentence as the first argument of the STRING_SPLIT() function and ' ' as the second argument. FROM STRING_SPLIT( 'An example sentence.
The curly braces are for complex variable expressions. They are interpreted by PHP, not by the SQL interface. $query = "SELECT * FROM users WHERE user='$_POST['username']' AND password='$_POST['password']'"; The above will lead to an parsing error.
We might require inserting a carriage return or line break while working with the string data. In SQL Server, we can use the CHAR function with ASCII number code. We can use the following ASCII codes in SQL Server: Char(10) – New Line / Line Break.
SQL Server allows the following (be careful to use single quotes instead of double)
UPDATE User SET UserId = 12345 , Name = 'J Doe' , Location = 'USA' , Bio='my bio spans multiple lines!' WHERE UserId = 12345
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With