Android Question SQL Server - column names in table

Declan

Well-Known Member
Licensed User
Longtime User
I am connecting to a remote Microsoft SQL Server database using RDC.
How can I query / obtain all the column/field names from a specific table?
 

edgar_ortiz

Active Member
Licensed User
Longtime User
I use this function...

B4X:
USE [MyDataBase]
GO
/****** Object:  UserDefinedFunction [dbo].[get_columns]    Script Date: 4/9/2016 9:20:07 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[get_columns](@table as varchar(MAX))
RETURNS  varchar(MAX)
as
begin
declare @ret as varchar(MAX)

select  @ret= COALESCE(@ret + ', ', '') + a.name from  sys.tables c
join sys.columns a on a.object_id =c.object_id
join sys.types b on a.system_type_id =b.system_type_id
where c.name=@table and a.is_identity<>1 and a.default_object_id =0
ORDER BY A.column_id


return @ret

END

Regards

Edgar
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…