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

SQL Insert from One Column to Another after CHARINDEX Query

$
0
0

Trying to copy part of some text out of 1 column in a table and insert it into a 2nd column.

I managed to get the following query to return the part thatI need which worked ok:

SQL
SELECTImportAll,left(ImportAll,charindex(',',ImportAll)-2)ASLeftStringFROMDocumentInventory.CompanyPri;

I used some Google searches for this and although it works does anyone know what the -2 does. When i change that number nothing changes in the output and although i understand the rest of the code I really don't know what that bit does. Just that it is needed.

So then I tried to get it to insert into the next column called DocumentSource. Insert Into didn't seem to work so I tried to store it in a variable and add it that way:

SQL
DECLARE@vDSnvarchar(100)SET@vDS=(SELECTImportAll,left(ImportAll,charindex(',',ImportAll)-2)ASLeftString...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



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