Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2006, 06:17 AM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default check if a column exists in the table

Hai,

    How do I find if a column is exists in a temp table?
I am creating a temp table and adding columns using ALTER TABLE in a loop,
but when same column name arrives it shows error. Please anyone help me.

Thanks in advace



 
Old April 21st, 2006, 02:28 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I'd have to ask 1) Why are you building the temp table this way, and 2) why would there be a duplicate column?

Where are you getting the list of columns from, and where are you building the temp table? I think if you provide a bit more information we might be able to help you a bit more.

 
Old April 21st, 2006, 11:08 PM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the immediate response, actually I am creating the temp table in a stored procedure. This procedure is for find the factory production
report all weeks in a year, as the production is based on the orders,I am getting repeat weeks. I solved this problem by using this code

SELECT
                SYSCOLUMNS.NAME AS [Column Name]
                FROM SYSOBJECTS
                    INNER JOIN SYSCOLUMNS ON SYSOBJECTS.ID = SYSCOLUMNS.ID
                    INNER JOIN SYSTYPES ON SYSTYPES.XTYPE = SYSCOLUMNS.XTYPE
            WHERE
                (OBJECTPROPERTY(SYSOBJECTS.id, N'IsUserTable') = 0
                AND SYSCOLUMNS.NAME = @ColumnName
                AND SYSOBJECTS.NAME = '##tempWeeklyProduction')
            ORDER BY SYSOBJECTS.NAME

thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie question: check if table exists in DB savoym Java Databases 4 March 9th, 2012 06:57 AM
how to check the username already exists in table asad_black ASP.NET 2.0 Basics 2 September 15th, 2008 07:19 AM
check whether a particular session exists or not chayanvinayak PHP How-To 1 May 1st, 2006 04:09 PM
How to test if a column exists in a table jtrifts SQL Server 2000 2 February 16th, 2006 02:25 PM
How to check if connection already exists Ciarano VB How-To 3 March 9th, 2004 10:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.