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 2008 Forums
 Transact-SQL (2008)
 store procedure with parameters

Author  Topic 

picasso
Starting Member

3 Posts

Posted - 2013-06-04 : 01:09:53
Sorry for re-posting. I posted it in the wrong section.

I have two tables that can be compared as follows:

Select Col1 from DBTables where ltrim(rtrim(Col1)) not in (select ltrim(rtrim(Col2)) from DBTables where Col2 is not null)
order by 1
Select Col2 from DBTables where ltrim(rtrim(Col2)) not in (select ltrim(rtrim(Col1)) from DBTables where Col1 is not null)
order by 1

I would like to create a SP that takes two parameters Col1 and COl2 (e.g. EXEC myStoreProc col1, col2)
any help is greatly appreciated

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-04 : 01:14:49
Hmm...why does your column nams come from a parameter? why does it change it runtime? Why not just write it static way as columns in table are fixed?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

picasso
Starting Member

3 Posts

Posted - 2013-06-04 : 19:13:56
Basically I want the user to choose two columns at a time and compare them.
I have a table with 16 columns but onlt two should be compared at a time

thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-04 : 23:48:56
then you need to use dynamic sql for that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-05 : 02:34:07
Refer these links for Dynamic SQL
http://www.codeproject.com/Articles/20815/Building-Dynamic-SQL-In-a-Stored-Procedure
http://www.sommarskog.se/dynamic_sql.html

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-05 : 02:42:11
Easiest way to do these kind of comparisons is to export column details to excel sheets from both tables and then use excel macros to do sheet comparisons.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -