This question already has answers here:
What is the meaning of the prefix N in T-SQL statements and when should I use it?
(4 answers)
Closed 4 months ago.
I have table in SQL Server with a column Team, but when inserting data through BCP, some special character are on the first line:
TEAM
1.Insta Acq
I tried with the code shown here, but with no success. I copied the special symbol and paste it in the replace function as
REPLACE(COLUMN NAME,'1.Insta Acq', '1.Insta Acq' )
Datatypes:
COLUMN_NAME DATA_TYPE TYPE_NAME
-------------------------------------
TEAM -9 nvarchar
SOURCE 12 varchar
STAGE 12 varchar
TARGET OCT'22 4 int
Sample data in the table:
TEAM SOURCE STAGE TARGET OCT'22
------------------------------------------------------------------
1.Insta Acq Website TB Active / TB Inactive 9000
1.Insta Acq Website No Offer 3500
Since you're dealing with "special" characters that are probably Unicode, you must use the N prefix in your REPLACE call to indicate that these are Unicode string literals you're working with.
Try this:
REPLACE(COLUMN NAME, N'1.Insta Acq', N'1.Insta Acq')
Related
This question already has answers here:
What is the meaning of the prefix N in T-SQL statements and when should I use it?
(4 answers)
Closed 3 years ago.
In a nvarchar(512) field if i store unicode chars like this:
UPDATE MYTABLE SET UNICODEFIELD = 'TレEホSᅯTル'
when i query it i get
T?E?S?T?
It looks like the "unusual" chars are not considered as unicode, i would expect the "?" behavior in case of varchar, while with nvarchar it should work fine, i am expecting
TレEホSᅯTル
as output, instead of
T?E?S?T?
Does anyone have an idea about this?
Because you're using a varchar, not an nvarchar. 'TレEホSᅯTル' = 'T?E?S?T?' as characters like レ can't be stored in a varchar.
Use a literal nvarchar:
UPDATE MYTABLE SET UNICODEFIELD = N'TレEホSᅯTル';
This question already has answers here:
How to cast the DateTime to Time
(3 answers)
Closed 4 years ago.
I have a column in a SQL Server database of datatype DATETIME.
Currently the value is in this format: 2054-12-31T00:00:00.0000000
I want to convert this column values into this format : 2054-12-31T00:00:00
This conversion of value should happen while I select the column in SELECT query statement at run time
DATETIME as stored in SQL Server doesn't have any "format" associated with it - it's stored as a binary, 8 byte value.
In order to convert that binary value into a human-readable format, you need to check out the different styles for CONVERTing a DATETIME column into a string representation: https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-2017
You're probably looking for style #126 - so you can use this in your SELECT query:
SELECT
CONVERT(VARCHAR(50), YourDateTimeColumn, 126)
and that should do it
This question already has answers here:
Using T-SQL, return nth delimited element from a string
(14 answers)
Closed 6 years ago.
I want to split a column string
This is the string :
Final Settlement Of Security Fee /BTS-15-0114/SYED AKHNOKH HUSSAIN
I want to split on the bases of '/', i want this result :
Final Settlement Of Security Fee
BTS-15-0114
SYED AKHNOKH HUSSAIN
and i want to get the middle string 'BTS-15-0114'
Does all the values is same format like you posted?
Here is a sample for your sample string.
DECLARE #s VARCHAR(max)='Final Settlement Of Security Fee /BTS-15-0114/SYED AKHNOKH HUSSAIN'
SELECT PARSENAME( REPLACE(#s,'/','.'),2)
WIll get:
BTS-15-0114
We are trying to pull data from external source (mssql) to postgres. But when i checked for invoicedate column entries are getting blank at the same time mssql is showing invoicedate values for those entries.
ie
We tried following query on both the DBMS:
When query executed in SQL Server:
select * from tablename where salesorder='168490'
getting 12 rows where invoicedate column is '2015-10-26 00:00:00.000'
But same query is executed on Postgres
select "InvoceDt" from tablename where salesorder='168490'
Getting 12 rows where the column invoicedate is null.
Question is why?
Postgres InvoiceDt column is coming null rather than we can see that SQL Server is showing appropriate data values.
Why is the data different between SQL Server and Postgres for this particular column?
Vicps, you aren't using Postgres and that is why a_horse_with_no_name is having such a hard time trying to understand your question. You are using Pivotal HDB (formally called HAWQ). HAWQ is now associated with the incubator project, "Apache HAWQ" and the commercial version is "Pivotal HDB".
Pivotal HDB is a fork of Pivotal Greenplum database which is a fork of PostgreSQL 8.2. It has many similarities to Postgres but it is most definitely not Postgres.
You are also using Spring-XD to move the data from SQL Server to HDFS which is critical in understanding what the true problem is.
You provided this example:
CREATE TABLE tablename ( "InvoiceDt" timestamp )
LOCATION ('pxf://hostname/path/to/hdfs/?profile=HdfsTextSimple')
FORMAT 'csv' ( delimiter '^' null 'null' quote '~');
Your file only has one column in it? How is this possible? Above, you mention the salesorder column. Secondly, have you tried looking at the file written by Spring-XD?
hdfs dfs -cat hdfs://hostname:8020/path/to/hdfs | grep 168490
I bet you have an extra delimiter, null character, or an escape character in the data which is causing the problem. You also may want to tag your question with spring-xd too.
[THIS IS NOT A QUESTION ABOUT NVARCHAR OR HOW TO STORE CHINESE CHARACTER]
SQL Server 2008 Express
Database collation is SQL_Latin1_General_CP1_CI_AS
create table sample1(val varchar(2))
insert into sample1 values(N'中文')
I know these Chinese characters would become junk characters.
I know I can use nvarchar to overcome all problem.
What I don't know is: why there isn't "string too long" error when I run the insert statement?
N prefix means that client will encode the string using UNICODE.
2 Chinese characters will become 4 bytes.
varchar(2) can only contain 2 bytes.
Why people down vote this question? really?
An implied cast takes place. This would work if "val" was created as nvarchar(2).
More explanation to #marc_s answer.
The character N'中文' will be converted to varchar with the collation SQL_Latin1_General_CP1_CI_AS. Since there is no such character in the code page, it will converted to not defined, and 0x3f3f in the end. 0x3f is the question mark, so there will be two question marks in this case and it won't exceed the column length.
Try to use NVARCHAR(...), NCHAR(...) datatypes -
CREATE TABLE dbo.sample1
(
val NVARCHAR(4)
)
INSERT INTO dbo.sample1
SELECT N'中文'