Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Spit column that has underscore to multiple columns and also calculate age.

$
0
0

I have a table called clients and I'm trying to split the value which contains underscore that is one column into multiple columns and I'm also trying to create a column that calculate the age of the person. Here is how the table looks like

USERIDVendors(dobyr)loginsource
10bta      yes       1976       yes    google_hope
25cwd      yes       1986       yes    google_hln_1045
45tyj      no        1990       no     bing_hln_4345
645io      no        1960       no     bing

The goal is to have that look like this:

USERID Vendors (dobyr) login Source1 Source2 Source3 Age

10bta yes 1976 yes google hope null 44 25cwd yes 1986 yes google hln 1045 34 45tyj no 1992 no bing hln 4345 28 645io no 1960 no bing null null 30

So far, I've only been able to calculate the age but haven't been able to parse the source column

select *, datepart(year, CURRENT_TIMESTAMP) - dobyr as Age
FROM client


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>