SQL Query - Avoid splitting of data into different columns

 One of the queries we received was as below - 


: Actually i have 2 fields. Field A and Field B.


2: When the Data A Field reaches the length of 10 Character, it moves the rest of the data into Field B... Therefore it gets splitted into 2 Fields.


When this situation happens, i want whole word should be moved into Field B, Instead splitting between Field A and Field B.


Could you please let me know how to write the query to fulfill this scenario?


Solution - 

Check the length of the Source data. If the length is greater than 10, fetch the value into Column B.

SQL Query can be something like below -

SELECT 

CASE WHEN len(Source.Value) <= 10 Then Source.Value

ELSE '' END AS ColA

CASE WHEN len(Source.Value) > 10 Then Source.Value

ELSE '' END AS ColB

FROM SourceTable



Post a Comment

Previous Post Next Post

Contact Form