Select "Request" for a fixed length

I have a table called a client, where I select several columns and fix its length, where I need to send values ​​to SSIS packets to output a fixed length and write to a text file

customerID:10 Mobilenumber:11 Emailaddress:256 select customerID,mobilenumber,Emailaddress from customer 

I want to make sure my customer ID is always 10, mobile number 11, email address 256.

+4
source share
1 answer

You can use them as fixed-type string data types, as in:

 select cast(customerID as char(10)) as customerID, cast(mobilenumber as char(11)) as mobilenumber, cast(Emailaddress as char(256)) as Emailaddress from customer 

If you encounter any oddities when working like this, it may be useful to save the ANSI_PADDING settings.

Another way to do this might be:

 select left(Emailaddress + replicate(' ', 256), 256) 

Although this method often simply applies similar logic from other languages ​​to T-SQL.

+6
source

Source: https://habr.com/ru/post/1437317/


All Articles