Combining two fields into a single field with a space between
CONCAT is a SQL Sever 2012 function and does not exists in previous version. If you run the sqlfiddle that sgeddes created, which is setup as MS SQL Sever 2012, the query runs. However, if you change it to MS SQL sever 2008 and rebuild the schema it throws an error. I assume you're not running 2012 because you're getting a concat error.
http://msdn.microsoft.com/en-us/library/hh231515.aspx
Wrapping the function in brackets will make it work but I don't see the need.
SOCALNoob hit the nail on the head. The + will combine columns and text together quite nicely. I don't see why the below would not work.
LTRIM(RTRIM(dbo.gpEmployeeList.firstName)) + ' ' + dbo.gpEmployeeList.LASTNAME) AS DisplayName
How to insert a space between two values in MySQL
You literally just need a space between $fname
and $lname
, like $fname $lname
. So, your whole code should look like this:
$new_user= mysqli_query($db,"INSERT INTO userinfo (id,firstname,lastname,email,pass,displayname) VALUES ('','$fname','$lname','$email','$db_pass','$fname $lname')");
Also, as @FreshPrinceOfSO says, you should use prepared statements. You have a potential SQL injection problem right now.
SQL print a space between concat statements
You don't mention what flavor of SQL you're using, but depending, you may need to convert the values to strings first. For SQLSever...
(Cast(NBR as varchar(20)) + ' ' + Cast(ACCT_NBR as varchar(20))) as acct,
SQL add space in column string
What you want is to update your column values with a concatenation of the first part of the name followed by the space ' '
, followed by the rest of the name.
UPDATE Customers
SET name = CONCAT(SUBSTRING(name, 1, 5),
' ',
SUBSTRING(name, 6));
How to add a space in one iteration of SQL query without effecting the other in my PHP
Since you're wanting different behavior for one specific condition, it seems like you could just check for that condition on output and modify the text if the condition is met rather than trying to do it in the query.
<?php echo $code[0] == 'TheOne' ? 'The One' : $code[0]; ?>
I may have misunderstood what you meant by "I don't want it to happen for every use", though. I assumed you meant other uses of the same query.
SQL Server 2014: Add space after comma
I'd first replace all instances of ,
(comma + space) with ,
(comma, NO space). That way everything is uniform. Then go the other way; replace commas with comma + space
Adding spaces before a value?
You need to apply string concatenation.
For MySQL and MariaDB
SELECT concat(' ', '00:99:88:aa') FROM ...
or in the event of an update
UPDATE ...
SET value = concat(' ', value)
For SQL Server
SELECT ' ' + '00:99:88:aa' FROM ...
or in the event of an update
UPDATE ...
SET value = ' ' + value
For MS Access
SELECT ' ' & '00:99:88:aa' FROM ...
or in the event of an update
UPDATE ...
SET value = ' ' & value
For all the others
SELECT ' ' || '00:99:88:aa' FROM ...
or in the event of an update
UPDATE ...
SET value = ' ' || value
space between 2 column names with php from sql
<option value="" >Valuer of this Property</option>
<?php
$res=mysqli_query($conn, "SELECT CONCAT(first,' ',surname) as full_name from listalot_users");
while($row=mysqli_fetch_array($res))
{
?>
<option><?php echo $row['full_name']; ?></option>
<?php
}
?>
</select>
Related Topics
Storing Image in Database Directly or as Base64 Data
How to Check If a SQL Server String Is Null or Empty
Select Only Rows With Max Date
How to Select the Last Record from MySQL Table Using SQL Syntax
Reactjs Connection With Database
Convert a 12 Hour Format to 24 Hour Format in SQL Server
How to Tell If a Value Is Not Numeric in Oracle
Joining the Table Conditionally in SQL
Selecting First and Last Values in a Group
Sqlcmd Not Able to Find a Library (Libmsodbcsql-17.0.So.1.1) That Is There
Sql Server Function to Return Minimum Date (January 1, 1753)
How to Return a Flag If Exist Id in Another Table MySQL
Mysql Convert Date from Mm-Dd-Yyyy to Yyyy-Mm-Dd Format
The Network Adapter Could Not Establish the Connection in SQL Developer
Postgresql How to Insert a Value With Double Quotes Inside Double Quotes
How Two Join to Tables Based on the Highest Value in One of Them