1

I want to do something like that:

declare @manufacture varchar(MAX)
declare @model varchar(MAX)
declare @version varchar(MAX)
declare @fipeId varchar(MAX)
set @manufacture = (select top 1 MarcaFipe from fipeNew where ModeloFipe like 'Palio%' group by MarcaFipe)
set @model = (select ModeloFipe replace(fipeNew.ModeloFipe, '%', 'Palio') from fipeNew where ModeloFipe like 'Palio%')
set @version = (replace(fipeNew.ModeloFipe, 'Palio ', '') from fipeNew where ModeloFipe like 'Palio%')
set @fipeId = (select CodigoFipe from fipeNew where ModeloFipe like 'Palio%')

UPDATE vehicle
SET vehicle.manufacture=@manufacture,
vehicle.model=@model,
vehicle.version=@version,
vehicle.fipeId=@fipeID

In short, I have the following table:

https://i.sstatic.net/Brvvo.png

Note: Couldn't post image because of my reputation.

I want to split the dbo.newFipe.ModeloFipe that has string like 'Palio%' and MarcaFipe='Fiat' and set the first word (Palio in this case) into dbo.vehicle.model and the rest of the substring into dbo.vehicle.version.

How can I do this?

Thanks in advance.

1 Answer 1

1

You can't insert into two tables in one statement.

You can use this query to get your values for insert:

select distinct left(ModeloFipe,charindex(' ',ModeloFipe)) as Model, right(ModeloFipe,len(ModeloFipe)-charindex(' ',ModeloFipe)) as Version
from dbo.newFipe
where ModeloFipe like 'Palio%' and MarcaFipe='Fiat'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.