SQL Server - SQL Server 2005

Asked By Keerthi Cheluvaraj
02-Sep-08 02:37 AM

Hi,

 I would like to know how to write the procdeure to get all the filed names(not the values) in this fomat.

 

(fieldname)field1 = @field(fieldname)

(fieldname)field2 = @field(fieldname)

 

and @fieldname1,@fieldname2,......

 

Please help me out.

Thank you.

Keerthi.Cheluvaraj.

reply  reply

02-Sep-08 02:53 AM
This way:
See the example:
CREATE PROCEDURE blockdet6(@pid char(20)) AS
select * from blockdet where projid=@pid

refer this code and below link  refer this code and below link

02-Sep-08 03:05 AM

SELECT table_name=sysobjects.name,
         column_name=syscolumns.name,
         datatype=systypes.name,
         length=syscolumns.length
    FROM sysobjects
    JOIN syscolumns ON sysobjects.id = syscolumns.id
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U'
ORDER BY sysobjects.name,syscolumns.colid


refer this link :

http://codesnippets.joyent.com/posts/show/337

try this...  try this...

02-Sep-08 03:22 AM

Hi,

try the below query...

SELECT '@' + COLUMN_NAME as 'ColName' FROM INFORMATION_SCHEMA.COLUMNS COLUMNS WHERE TABLE_NAME ='table NAme'

Use this  Use this
02-Sep-08 03:27 AM

Use this:

SELECT syscolumns.name AS FieldsInTable FROM sysobjects

JOIN syscolumns ON sysobjects.id = syscolumns.id

WHERE sysobjects.name = 'spt_values' //Put your table name here

To get the Schema Information of Tables.  To get the Schema Information of Tables.
02-Sep-08 04:33 AM

Hello

--- Run this Query using the database for which you want to know the details 

SELECT sysobjects.name TableName, syscolumns.name ColumnName,

systypes.name + '(' + cast(syscolumns.length/ (Case When systypes.name Like '%Char%'

Then SysColumns.TypeStat Else 1 End) as varchar) + ') ' DateTypeLength,

isNull(syscolumns.collation,'') Collation,

case when syscolumns.isnullable = 1 then 'NULL' else 'NOT NULL' end NUllStatus

from syscolumns

inner join sysobjects

on sysobjects.id = syscolumns.id

inner join systypes

on systypes.xtype = syscolumns.xtype

where

-- If you want Only the Columns with collation set

--syscolumns.collation is not null and

sysobjects.xtype = 'U' and SysColumns.Xtype <> 231 

and sysobjects.name Like '%tablename%'

Order By SysObjects.id desc

 

Regards

 

Thanks but the format?  Thanks but the format?
02-Sep-08 10:25 PM

HI,

Thank you very much it works,but how do I get in this format

 

1st Format

(field1  and @field is fieldname. I need to have@symbol)

field1 = @field

field2 = @field

 

2nd Format, all the filed names should come in one row separated by comma (,)

@fieldname1,@fieldname2,......

 

Thank you very much

 

Format?  Format?
02-Sep-08 10:25 PM

HI,

Thank you very much it works,but how do I get in this format

 

1st Format

(field1  and @field is fieldname. I need to have@symbol)

field1 = @field

field2 = @field

 

2nd Format, all the filed names should come in one row separated by comma (,)

@fieldname1,@fieldname2,......

 

Thank you very much

Please let me know to get it in this format  Please let me know to get it in this format
02-Sep-08 10:26 PM

HI,

Thank you very much it works,but how do I get in this format

 

1st Format

(field1  and @field is fieldname. I need to have@symbol)

field1 = @field

field2 = @field

 

2nd Format, all the filed names should come in one row separated by comma (,)

@fieldname1,@fieldname2,......

 

Thank you very much

Please let me know in this format  Please let me know in this format
02-Sep-08 10:27 PM

HI,

Thank you very much it works,but how do I get in this format

 

1st Format

(field1  and @field is fieldname. I need to have@symbol)

field1 = @field

field2 = @field

 

2nd Format, all the filed names should come in one row separated by comma (,)

@fieldname1,@fieldname2,......

 

Thank you very much

Please let me know in this format  Please let me know in this format
02-Sep-08 10:27 PM

HI,

Thank you very much it works,but how do I get in this format

 

1st Format

(field1  and @field is fieldname. I need to have@symbol)

field1 = @field

field2 = @field

 

2nd Format, all the filed names should come in one row separated by comma (,)

@fieldname1,@fieldname2,......

 

Thank you very much

Fomrat?  Fomrat?
02-Sep-08 10:31 PM

HI,

Thank you very much it works,but how do I get in this format

 

1st Format

(field1  and @field is fieldname. I need to have@symbol)

field1 = @field

field2 = @field

 

2nd Format, all the filed names should come in one row separated by comma (,)

@fieldname1,@fieldname2,......

 

Thank you very much

try this...  try this...
03-Sep-08 12:08 AM

Hi,

try the below one...


DECLARE @column VARCHAR(4000)
 
SELECT
    @column = COALESCE(@column + ',', '') + '@' + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS COLUMNS WHERE TABLE_NAME ='tableName'
 
SELECT Colors =  @column

Thanks Vasanth  Thanks Vasanth
03-Sep-08 12:15 AM

Vasanth,

 

Thank you very much its giving me the fields name like in single row. Thank a lot.

But could you help me out for the other format  field1 = @field

Thanks a lot,Thank you very much.

try this....  try this....
03-Sep-08 12:21 AM

Hi,

what is exact requriement?... should the coulmns like this

field1=@field1,field2=@field2,.....

then here is the code for this

DECLARE @column VARCHAR(4000)
 
SELECT
    @column = COALESCE(@column + ',', '') +  COLUMN_NAME + '=@' + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS COLUMNS WHERE TABLE_NAME ='tableName'
 
SELECT Colors =  @column

But one below the other  But one below the other
03-Sep-08 12:25 AM

Vasanth,

yes exactly but should be one below the other like

field1 = @field

field2 = @field

......

.....

......

 

Thank you.

try this...  try this...
03-Sep-08 12:30 AM

Hi,

do you require two formats sepertely, find the query for this...

format1:

select COLUMN_NAME + '=@' + COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS COLUMNS WHERE TABLE_NAME ='tableName'

Format2:

DECLARE @column VARCHAR(4000)
 
SELECT
    @column = COALESCE(@column + ',', '') + '@' + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS COLUMNS WHERE TABLE_NAME ='tableName'
 
SELECT Colors =  @column

Thank you very much,Its working fantastic !!!!!  Thank you very much,Its working fantastic !!!!!
03-Sep-08 12:34 AM

Vasanth,

Thank you very much.

You helped me a lot. I never forget your help.

Can I know you?

Thank you very much Vasanth,May God Bless you.

hi...  hi...
03-Sep-08 01:09 AM

Hi,

thanks... inacse of any issue, you can get a lot of help from this forum... you can post here...

this is my mail id...

vasanth.kumar.d@gmail.com

OK,Thanks.  OK,Thanks.
03-Sep-08 01:11 AM
Thanks Vasanth,Thank you very much
How it workds  How it workds
22-Sep-08 02:50 AM

Hi Vasanth,

 

Could you please explain me how it works?

 

Do anybody knows how to doccument a stored procedure? I need to document this.

 

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER proc [dbo].[MasUpdate]

@overrideFlag bit = 0 ,-- to override incomplete loads.

@ErrorMessage varchar(500) = 'OK' output

as

/*

$History: $

*/

declare @rwCount int , @runid int

declare @errorCode int, @rc int

declare @dbname varchar(100), @hostname varchar(100),@errorProc varchar(100)

-- set default values

select @hostname=@@SERVERNAME,@dbname=db_name(),@errorProc='MASUpdate'

 

begin try

-- check if there are any updates that are running ...

if exists ( select 1 from MM_UpdateMaster where runflag = 'n') and (@overrideFlag = 0)

begin

RAISERROR(60000,16,1,@hostname,@dbname,@errorProc)

end

-- setup run

insert into MM_UpdateMaster (runFlag) values ('n')

set @runid = @@identity

-- Upload entity

execute @RC = MasEntityCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload vehicle

execute @RC = MasVehicleCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload vehicleIvu

execute @RC = MasVehicleIVUCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload IAC

execute @RC = MasIacCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- run complete ....

update MM_UpdateMaster set runFlag = 'y' where runid=@runid

end try

begin catch

set @errorCode = @@error

set @ErrorMessage = error_message()

return @errorCode

end catch

return 1

Documenting the stored procedure  Documenting the stored procedure
24-Sep-08 02:30 AM

Could you please explain me how document this procedure..its very urgent please....

like exactly how we get when we type sp_ in SQl help..Iam very much confused with brackets to use like { [

 

Please help me out .....

 

 

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER proc [dbo].[MasUpdate]

@overrideFlag bit = 0 ,-- to override incomplete loads.

@ErrorMessage varchar(500) = 'OK' output

as

/*

$History: $

*/

declare @rwCount int , @runid int

declare @errorCode int, @rc int

declare @dbname varchar(100), @hostname varchar(100),@errorProc varchar(100)

-- set default values

select @hostname=@@SERVERNAME,@dbname=db_name(),@errorProc='MASUpdate'

 

begin try

-- check if there are any updates that are running ...

if exists ( select 1 from MM_UpdateMaster where runflag = 'n') and (@overrideFlag = 0)

begin

RAISERROR(60000,16,1,@hostname,@dbname,@errorProc)

end

-- setup run

insert into MM_UpdateMaster (runFlag) values ('n')

set @runid = @@identity

-- Upload entity

execute @RC = MasEntityCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload vehicle

execute @RC = MasVehicleCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload vehicleIvu

execute @RC = MasVehicleIVUCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload IAC

execute @RC = MasIacCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- run complete ....

update MM_UpdateMaster set runFlag = 'y' where runid=@runid

end try

begin catch

set @errorCode = @@error

set @ErrorMessage = error_message()

return @errorCode

end catch

return 1

Documenting stored procudre  Documenting stored procudre
24-Sep-08 02:31 AM

Could you please explain me how document this procedure..its very urgent please....

like exactly how we get when we type sp_ in SQl help..Iam very much confused with brackets to use like { [

 

Please help me out .....

 

 

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER proc [dbo].[MasUpdate]

@overrideFlag bit = 0 ,-- to override incomplete loads.

@ErrorMessage varchar(500) = 'OK' output

as

/*

$History: $

*/

declare @rwCount int , @runid int

declare @errorCode int, @rc int

declare @dbname varchar(100), @hostname varchar(100),@errorProc varchar(100)

-- set default values

select @hostname=@@SERVERNAME,@dbname=db_name(),@errorProc='MASUpdate'

 

begin try

-- check if there are any updates that are running ...

if exists ( select 1 from MM_UpdateMaster where runflag = 'n') and (@overrideFlag = 0)

begin

RAISERROR(60000,16,1,@hostname,@dbname,@errorProc)

end

-- setup run

insert into MM_UpdateMaster (runFlag) values ('n')

set @runid = @@identity

-- Upload entity

execute @RC = MasEntityCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload vehicle

execute @RC = MasVehicleCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload vehicleIvu

execute @RC = MasVehicleIVUCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- Upload IAC

execute @RC = MasIacCsr @vRunId= @runid -- default @vLogging = 3 for all records

-- run complete ....

update MM_UpdateMaster set runFlag = 'y' where runid=@runid

end try

begin catch

set @errorCode = @@error

set @ErrorMessage = error_message()

return @errorCode

end catch

return 1

Create New Account
help
replication sql 2000 - -> sql 2005 SQL Server , sql, 2005" / > Is it possible to replicate a db from sql server 2000 to sql server 2005? When I set the publications, I look this "select
SSIS for SQL Server 2005? SQL Server How do I download SSIS for SQL Server 2005? SQL Server Programming Discussions SQL Server 2005 (1) Distributed (1) Imp (1) Exp (1) E5C6F1F60688
DTS in SQL Server 2005 SQL Server With the SQL server 2005, how can I invoke DTS? Should I install 'SQL Server Business Intelligence Development Studio'? If
Where is my SQL Server 2005 ? SQL Server I installed SQL Server 2005 on my machine, but when I go to the SQL Server Management Studio and connect
Cannot open server 2000 file in SQL SERVER 2005 SQL Server I installed SQL SERVER 2005 replacing SQL SERVER 2000 and now I cannot open the 2000 database file. Do