Go4Expert (http://www.go4expert.com/)
-   Database (http://www.go4expert.com/forums/database-forum/)
-   -   Need help with sql select query (http://www.go4expert.com/forums/help-sql-select-query-t19067/)

murlock1988 16Aug2009 16:20

Need help with sql select query

I'm currently doing a project using C#.net and sql server 2005, and I've run into a problem with a select statement! This select statment has to select all column names of a certain table (this is specified in the variable tablename) but i dont want it to include the column names of type int. Please could you help me with this? Here is the select statement i'm currently trying to us but get the error: "System.Data.SqlClient.SqlException: Invalid column name 'DATA_TYPE'."


cmd.CommandText = "SELECT [name] AS [Column name] FROM syscolumns WHERE id = (SELECT id  FROM sysobjects WHERE type = 'U' AND [NAME] = '" + tablename + "') AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')";
Thanks in advance!!

night.rider 16Aug2009 20:16

Re: Need help with sql select query
Dont give 2 select commands in one statement. as once one Query is running the other is not called .. as u initiated the first query second will not work. so use second to get the result and then put in 1st..

nimesh 23Aug2009 03:37

Re: Need help with sql select query
that's not the problem.

as the error indicates the problem is with the select statement at "data_type"
Invalid column name 'DATA_TYPE'

if you check the columns for systables, do you see and column with name DATA_TYPE
check here - http://msdn.microsoft.com/en-us/library/ms186816.aspx

to check if your query runs properly, first execute the select statement in any sql client replacing the variables with values and then use it in the code

All times are GMT +5.5. The time now is 14:18.