Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous column name when same column is in two tables #83

Open
ax3ld opened this issue Jan 26, 2022 · 2 comments
Open

Ambiguous column name when same column is in two tables #83

ax3ld opened this issue Jan 26, 2022 · 2 comments

Comments

@ax3ld
Copy link

ax3ld commented Jan 26, 2022

Hello,

I'm trying to export certain columns from a join, but since a column is in more than one table, I'm using table aliases.

EXEC sp_generate_merge 'actionXRole', @disable_constraints = 1, @delete_if_not_matched = 0, @nologo = 1, @include_use_db = 0, @schema = 'dbo', @debug_mode = 1, @ommit_generated_always_cols = 1, @cols_to_include = "'ActionXSecurityRoleid','asr.actionid','securityroleid'", @from ='from dbo.actionXRole asr inner join dbo.action a on a.actionid = asr.actionid where a.name = ''CharismaManualDisbursement'''

I've specified @cols_to_include with an alias for asr.actionid but it's excluded from the end result.
I've used @debug_mode to see what's happening and the debug made me realize that the alias is not properly placed.

SELECT ' ' + CASE WHEN ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) = 1 THEN ' ' ELSE ',' END + '('+ COALESCE('N''' + REPLACE(CONVERT(char(36),RTRIM([ActionXSecurityRoleid])),'''','''''')+'''','NULL')+',' + COALESCE('N''' + REPLACE(CONVERT(char(36),RTRIM([securityroleid])),'''','''''')+'''','NULL')+',' + COALESCE('N''' + REPLACE(CONVERT(char(36),RTRIM(asr.[actionid])),'''','''''')+'''','NULL') +')' from EbsMetadata.actionXSecurityRole asr inner join EbsMetadata.action a on a.actionid = asr.actionid where a.name = 'CharismaManualDisbursement'

With the alias like RTRIM(asr.[actionid])) the query works, but if I try to put it inside like RTRIM([asr.actionid])) it's not working.

It's there a parameter that can be used or this script it's not working with table aliases?

Thanks,
Alex

@dnlnln
Copy link
Owner

dnlnln commented Feb 6, 2022

I'll have to look into that one. As a workaround, if you haven't tries this already, maybe try using a common table expression in the @from param so that it isn't necessary to use table aliases in the @cols_to_include param?

@ax3ld
Copy link
Author

ax3ld commented Feb 7, 2022

Hi,

I will give it a try. In the meantime, I did it with a subquery and it worked.

Thanks,
Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants