I have following query
select * from table1
if table1 contains text type column/columns then I need only 100 characters
Assume, End User don’t know the schema(columns name) of table,Just know table name
Executing this query from query analyzer that is front end application.
User writer query in textarea and executes
*I am Using SqlServer2005
Dont use substring function in query from frond end
I can use substring function on text columns in C# code but I want this in database end.
*
If I understand correctly, you want the user to specify a table name, and get in return the result of SELECT * FROM with all the text fields limited to 100 characters, and all that on the database side?
Seems to me you need to create a stored procedure to do that. Your input parameter would be the table name, then you’ll go on querying the table’s structure, and build a dynamic SELECT statement that uses the SQL substring on text fields larger than 100 characters. Run the dynamic SQL statement inside your stored procedure, and that will be your result.
To get the table structure, just run the stored procedure
sp_helpwith the table name as a parameter. The result will contain the column names and types. Loop over it to build your dynamic SQL statement.