Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Structure of Table-1:-
--------------------
Table_1_ID bigint,
AreaID bigint,
Name Varchar(50)
etc.....

Structure of Table-2:-
--------------------
Table_2_ID bigint,
AreaID bigint,
Name Varchar(50)
etc.....

I want to do that, how will i compare the data type is same of two tables by specifying same field name(i.e. AreaID) through T- Sql Query in SQL SERVER 2000??

Please help me the above problem....
Posted

See if this helps...

SQL
declare @datatype1 varchar(50)
declare @datatype2 varchar(50)

--- Get the datatype of Firstfield
SELECT @datatype1 = DATA_TYPE
FROM information_schema.columns
WHERE table_schema = 'dbo'
AND table_name = 'Table_1'
AND column_name = 'AreaID' ;

--- Get the datatype of Secondfield
SELECT @datatype2 = DATA_TYPE
FROM information_schema.columns
WHERE table_schema = 'dbo'
AND table_name = 'Table_2'
AND column_name = 'AreaID' ;

select 'true' where  @datatype1 = @datatype2
 
Share this answer
 
While the answer from JimJos is very good, I think that if this is a real scenario, you should rethink the design of the database: Why do you want to store the same data in separate table.

In order to keep things simple, consider adding an extra column to the table which would help to categorize the data. This way you wouldn't need to have two separate tables.

But again, this applies if the scenario you posted is (near) real :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900