Question

When writing strings to a SQL-Server database, leading blanks are removed. Is there a way to change this behaviour?


When writing strings to a SQL-Server database, leading blanks are removed. Is there a way to change this behaviour?

5 replies

Userlevel 2
Badge +10

Hi @m_breithecker​ what data type are the attributes that you're writing to your database? (A screenshot would be really helpful)

So far, I've been able to create a new table in my SQL-Server database with the attribute types set to varchar and char, and the leading blanks are preserved. In the writer feature type, under the User Attributes tab, set the Attribute Definition to Manual, and then set your attribute types to one of either varchar or char and test if that fixes the issue.

image 

Thanks,

Dan M

Hi @m_breithecker​ what data type are the attributes that you're writing to your database? (A screenshot would be really helpful)

So far, I've been able to create a new table in my SQL-Server database with the attribute types set to varchar and char, and the leading blanks are preserved. In the writer feature type, under the User Attributes tab, set the Attribute Definition to Manual, and then set your attribute types to one of either varchar or char and test if that fixes the issue.

image 

Thanks,

Dan M

Hi Dan,

thanks for your reply. Maybe the datatype really is the problem, because in my case it's nvarchar:

 

imageI'm not sure, if I should change it in FME, because that is what the definition in the SQL-Server database is like:

 

imageThanks

Martina

Userlevel 2
Badge +10

Hi Dan,

thanks for your reply. Maybe the datatype really is the problem, because in my case it's nvarchar:

 

imageI'm not sure, if I should change it in FME, because that is what the definition in the SQL-Server database is like:

 

imageThanks

Martina

@m_breithecker​ thanks for the additional details. I've tested nvarchar as well and the leading blanks are preserved in my output table (both when creating a new table and when writing to an existing table in SQL Server). So I can't seem to reproduce the issue you're getting.

What version of FME Workbench are you running on your machine? Would you be able to provide a small sample (one or two rows) of the data for those columns that are losing their leading blanks? If you're not comfortable sharing your data here, you can upload it to our Safe Support FTP.

 

Thanks

Hi Dan,

thanks for your reply. Maybe the datatype really is the problem, because in my case it's nvarchar:

 

imageI'm not sure, if I should change it in FME, because that is what the definition in the SQL-Server database is like:

 

imageThanks

Martina

Hi @danminneyatsaf​ ,

as everything was working fine in your test, I went through all the transformers in my workbench to find out, if the blanks are lost before writing to the database. I found out that the reason was an attribute splitter with the wrong parameter setting.

Sorry for the trouble!

Userlevel 2
Badge +10

Hi Dan,

thanks for your reply. Maybe the datatype really is the problem, because in my case it's nvarchar:

 

imageI'm not sure, if I should change it in FME, because that is what the definition in the SQL-Server database is like:

 

imageThanks

Martina

@m_breithecker​ glad that's working for you now! Always worth asking a question on the community even if you're not sure what the cause might be.

Reply