Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Store Procedure

Author  Topic 

avarndel
Starting Member

5 Posts

Posted - 2007-08-08 : 15:34:01
I'm New to SQL and I'm trying to do something which sounds easy, but seems to be complicated to code.

I have two tables. Table A has a column called ColName and isViewable
Table B has columns called role, source, etc.

I want to check in Table A where ColName = Table B column and is Viewable.

This is as far as I got so far. Your help will be much appreciated.

Set nocount on
declare @viewColumns VarChar(15),
@budgetColumns as VarChar(15),
@Columns as VarChar(15),
@count int ,
@count2 int,
@count3 int

SELECT @count=1
SELECT @count2=1
SELECT @viewColumns (Select FeeColName from xFeeColumns where IsViewable='1')
SELECT @budgetColumns (Select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME ='xBudgetNodeFees')

if @viewColumns[@count] = @budgetColumns[@count]
begin
select @columns = @viewColumns
Select @count3= @count3+1
end

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-08-08 : 16:35:16
Not sure I get what your desired result should be, does this work?
SELECT
*
FROM
TableA
INNER JOIN
TableB
ON TableA.ColName = TableB.[Column]
WHERE
TableB.IsViewable = 1
Go to Top of Page

avarndel
Starting Member

5 Posts

Posted - 2007-08-09 : 07:32:31
That means I have to check each column in Budget to see if it is viewable. Is that correct? Is there a way I can check all of them at once? I'm trying to get data from xBudgetNodeFees where in xFeeColumns indicate that it is viewable.

SELECT * FROM xBudgetNodeFees
INNER JOIN
xFeeColumns
ON xBudgetNodeFees.ColName=xFeeColumns.[FeeColName]
WHERE xFeeColumns.IsViewable = '1'
Go to Top of Page
   

- Advertisement -