March 26, 2012 at 10:03 am
Hi all,
I appreciate that when joining, I'm adding columns to (example) table1, from table2 - and you can do this conditionally.
But how can you add rows ? I am trying to union two tables together, but I want to add the second table's rows based on a table comparison condition too
Maybe there is a flavour of join that'll do this ?
Regard, Greg.
March 26, 2012 at 10:06 am
Really can't help you based on what you have posted so far. We can't see from here what you see there. Please post the code you are working with, the DDL (CREATE TABLE statement(s)) for the table(s) involved, sample date (a series of INSERT INTO statements) for the table(s), and the expected results based on the sample data.
March 26, 2012 at 10:55 am
I might be able to put up some test data when back in the office, but was wonder from a syntactical perspective if this was possible.
G
March 26, 2012 at 11:09 am
Not knowing what you are actually trying to accomplish, hard to say. I don't want to just take shots in the dark and hope it solves your problem.
March 26, 2012 at 1:01 pm
sorry, wrong post.
😛
____________________________________________________________________________
Rafo*
March 26, 2012 at 1:13 pm
xRafo (3/26/2012)
That data r results from a dynamic query,well that result i input to a temporary table, and then i made a update.
my test query:
DECLARE @sql NVARCHAR(MAX)
DECLARE @colCampoREPLACE VARCHAR(MAX)
DECLARE @C INT=1
DECLARE @cc INT=10
SET @colCampoREPLACE=''
BEGIN
--'C'+CONVERT(VARCHAR,@C)
SET @colCampoREPLACE = @colCampoREPLACE + 'c'+ CONVERT(VARCHAR(2),@C) +'='''','
SET @C=@C+1
END
SET @colCampoREPLACE=SUBSTRING(@colCampoREPLACE,1,LEN(@colCampoREPLACE)-1)
print @colCampoREPLACE
SET @sql='
UPDATE #tbl_Cron
SET '+@colCampoREPLACE+'
WHERE NIVEL_partida_cliente in (1,2,3)
'
EXEC sp_executesql @sql
print @sql
The problem was solved, but maybe exists anothe best way :ermm:
Me thinks you posted in the wrong thread.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply