That would only happen if PostCode
is missing a space. You could add conditionality such that all of PostCode
is retrieved should a space not be found as follows
select SUBSTRING(PostCode, 1 , case when CHARINDEX(' ', PostCode ) = 0 then LEN(PostCode) else CHARINDEX(' ', PostCode) -1 end)
Related Posts:
- T-SQL split string
- How to delete duplicate rows in SQL Server?
- SQL Query with NOT LIKE IN
- An attempt was made to access a socket in a way forbidden by its access permissions
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How can I delete using INNER JOIN with SQL Server?
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How can I get column names from a table in SQL Server?
- MS SQL compare dates?
- MS SQL compare dates?
- How do I fix ‘Invalid character value for cast specification’ on a date column in flat file?
- What is the maximum characters for the NVARCHAR(MAX)?
- Using RegEx in SQL Server
- sql query to return differences between two tables
- How to select the last record of a table in SQL?
- Comma separated results in SQL
- SHOWPLAN permission denied in database ‘tempdb’. in sql server 2008
- What do Clustered and Non-Clustered index actually mean?
- SQL query to get the employee name and their manager name from the same table
- Rename column SQL Server 2008
- Efficiently convert rows to columns in sql server
- How to turn IDENTITY_INSERT on and off using SQL Server 2008?sql-server-2008
- The SQL OVER() clause – when and why is it useful?
- Update multiple columns in SQL
- SQL Server IF EXISTS THEN 1 ELSE 2
- T-SQL split string based on delimiter
- SQL Query with SUM with Group By
- SQL Server Management Studio, how to get execution time down to milliseconds
- How do I perform an IF…THEN in an SQL SELECT?
- SQL update from one Table to another based on a ID match
- Enable ‘xp_cmdshell’ SQL Server
- How to drop all tables from a database with one SQL query?
- SQL Server : Arithmetic overflow error converting expression to data type int
- Optimistic vs. Pessimistic locking
- How to calculate percentage with a SQL statement
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- The target principal name is incorrect. Cannot generate SSPI context
- Query comparing dates in SQL
- The EXECUTE permission was denied on the object ‘xxxxxxx’, database ‘zzzzzzz’, schema ‘dbo’
- What is the meaning of the prefix N in T-SQL statements and when should I use it?
- BCP error “Unable to open BCP host data-file”
- Delete all the records
- Query error with ambiguous column name in SQL
- How to drop all tables from a database with one SQL query?
- How to find sum of multiple columns in a table in SQL Server 2005?
- Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
- Keeping it simple and how to do multiple CTE in a query
- How can I truncate a datetime in SQL Server?
- How to upsert (update or insert) in SQL Server 2005
- Why use a READ UNCOMMITTED isolation level?
- SQL Server WITH statement
- SQL Server Insert if not exists
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server
- How can I import an Excel file into SQL Server?
- SQL Server: Invalid Column Name
- How to group by month from Date field using sql
- sql server invalid object name – but tables are listed in SSMS tables list
- SQL – The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904)
- Is there a combination of “LIKE” and “IN” in SQL?
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- How to get a date in YYYY-MM-DD format from a TSQL datetime field?
- Search text in stored procedure in SQL Server
- How to convert SQL Server’s timestamp column to datetime format
- Arithmetic overflow error converting expression to data type datetime. (while displaying date time..)
- Arithmetic overflow error converting numeric to data type numeric
- ClassNotFoundException – com.microsoft.jdbc.sqlserver.SQLServerDriver
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Sql query to insert datetime in SQL Server
- The SELECT permission was denied on the object ‘Users’, database ‘XXX’, schema ‘dbo’
- How do you open an SDF file (SQL Server Compact Edition)?
- Trouble Connecting to sql server Login failed. “The login is from an untrusted domain and cannot be used with Windows authentication”
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- Bulk load data conversion error (truncation)
- Difference between database and schema
- Why do table names in SQL Server start with “dbo”?
- How to format a numeric column as phone number in SQL
- ‘Microsoft.ACE.OLEDB.16.0’ provider is not registered on the local machine.
- SQL Server Linked Server Example Query
- How do I format a number with commas in T-SQL?
- How do I fix the error ‘Named Pipes Provider, error 40 – Could not open a connection to’ SQL Server’?
- SQL: IF clause within WHERE clause
- Can I use multiple “with”?
- How to connect to local instance of SQL Server 2008 Express
- Errors: “INSERT EXEC statement cannot be nested.” and “Cannot use the ROLLBACK statement within an INSERT-EXEC statement.” How to solve this?
- SQL datetime compare
- Backup a single table with its data from a database in sql server 2008
- To add server using sp_addlinkedserver
- How to connect to a local database in SQL Server Management Studio?
- how to increment integer Columns value by 1 in SQL
- How can I group by date time column without taking time into consideration
- Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00
- What are named pipes?
- Format of the initialization string does not conform to specification starting at index 0
- SQL- Ignore case while searching for a string
- SQL WHERE.. IN clause multiple columns
- Filter data based on date in sql
- Varchar invalid for Sum operator
- What is tableName.* in SQL
- How to connect to database from Unity