September 9, 2009 at 10:01 am
Hi!
scenario: I want to insert data in rows from specific conditions.
select anadesc,idenvaseana,idegrupoana,matid,tipaid
from dbo.analisis
where (anadesc like '%disuelto%') and (matid = 'am') and (tipaid = 'mt')
How can i insert the data in the output of this consult?
thanks in advance.
September 9, 2009 at 11:37 am
Assuming your target table is called TargetTable, your code should look something like this:
INSERT TargetTable (anadesc,idenvaseana,idegrupoana,matid,tipaid)
select anadesc,idenvaseana,idegrupoana,matid,tipaid
from dbo.analisis
where (anadesc like '%disuelto%') and (matid = 'am') and (tipaid = 'mt')
September 9, 2009 at 11:58 am
benyos (9/9/2009)
Assuming your target table is called TargetTable, your code should look something like this:
INSERT TargetTable (anadesc,idenvaseana,idegrupoana,matid,tipaid)
select anadesc,idenvaseana,idegrupoana,matid,tipaid
from dbo.analisis
where (anadesc like '%disuelto%') and (matid = 'am') and (tipaid = 'mt')
thanks man!!
i guess i should add de values command
INSERT TargetTable (anadesc,idenvaseana,idegrupoana,matid,tipaid)
VALUES (1,2,3,4,5)
select anadesc,idenvaseana,idegrupoana,matid,tipaid
from dbo.analisis
where (anadesc like '%disuelto%') and (matid = 'am') and (tipaid = 'mt')
[/quote]
September 9, 2009 at 12:31 pm
Not sure what you're trying to do here...
You have an "insert...values..." command and then "select...where..."
What are you trying to achieve? Do you mean to update records that correspond to specific criteria or insert new ones?
September 9, 2009 at 12:50 pm
benyos (9/9/2009)
Not sure what you're trying to do here...You have an "insert...values..." command and then "select...where..."
What are you trying to achieve? Do you mean to update records that correspond to specific criteria or insert new ones?
i want to insert new records that correspond to specific criteria.
September 9, 2009 at 1:50 pm
i want to insert new records that correspond to specific criteria.
That means:
1. You are inserting new records
2. You specify values for the new records so they match certain criteria.
In this case, you code would look like this...
INSERT TargetTable (anadesc,idenvaseana,idegrupoana,matid,tipaid)
VALUES ('some string that contains disuelto like this record just did','idenvaseana goes here','idegrupoana goes here','am','mt')
And your values may come from 'values' list like I showed here or another select on a table, like I first posted
September 9, 2009 at 2:08 pm
benyos (9/9/2009)
i want to insert new records that correspond to specific criteria.
That means:
1. You are inserting new records
2. You specify values for the new records so they match certain criteria.
In this case, you code would look like this...
INSERT TargetTable (anadesc,idenvaseana,idegrupoana,matid,tipaid)
VALUES ('some string that contains disuelto like this record just did','idenvaseana goes here','idegrupoana goes here','am','mt')
And your values may come from 'values' list like I showed here or another select on a table, like I first posted
thanks benyos!
i will try it and post my results 😀
September 9, 2009 at 3:40 pm
hi!
to any other noobs around here...the solution.:-D :
update dbo.analisis
set idegrupoana = '10'
where (matid = 'am') and (tipaid = 'mt')and(idegrupoana is NULL)and
(anadesc like '%disuelto%')
it worked like a charm.!!
thanks to sql server central!! 😉
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply