Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Create a computed Column based on information from a column SQL

$
0
0

Hi,

I have a Database with the following columns:

Text
Project FileName Test Testing AA_AAB AA_BBC_123_23894945 AA_AAB AA_BBC_222_443342_E Test2 Testing444 

I'm trying to create a computed field where I can obtain a new Column Site based on the FileName position:

Text
Project FileName Site Test Testing TEST AA_AAB AA_BBC_123_23894945 123 AA_AAB AA_BBC_222_443342_E 222 Test2 Testing444 TEST2 

I have been testing with a CASE statement to create this extra column, but it seems fail to compute when it hits the project AA_AAB:

SQL
SelectProject,Filename,CASEWHENProject='AA_AAB'THEN(right([FileName],charindex('_',([FileName]))-1))ELSEProjectENDASSITEFromDB

Any pointers on this please?


Viewing all articles
Browse latest Browse all 4871

Trending Articles



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