Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generate SQL

Author  Topic 

Msandlana
Starting Member

33 Posts

Posted - 2008-07-04 : 02:20:15
Hi every I'm try create a store procedure that will generate code to update,insert or delete into a specific table. The user must be able to enter a table name, and values that he want to update, insert or delete. The procedure must check if the table exist and retrieve columns for that columns. Here i have two function 1. to check table exist, 2. to get columns and 3. a simple hardcoded procedure to generate SQL it must have 3 parameters @Operation,@tablename and @colums
1.
ALTER FUNCTION [dbo].[CheckTableNames]
(
@tableName varchar(50)
)
RETURNS bit
AS
BEGIN
IF exists (SELECT NAME FROM sysobjects WHERE xtype = 'U' AND name = @tableName)
BEGIN
RETURN 'True'
END
RETURN 'False'
END

2.
ALTER FUNCTION [dbo].[GetColumnNames]
(
@tableName varchar(50)
)
RETURNS TABLE
AS
RETURN
(
SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = @tableName AND xtype = 'U')
)
--SELECT * FROM dbo.GetColumnNames('Store')

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-07-04 : 04:59:39
Do you have a question?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-07-04 : 14:13:16
I have one:
WHY ARE YOU DOING THIS?!

e4 d5 xd5 Nf6
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-07-07 : 02:51:48
Maybe he likes pain.

My main system is a bit like this. I'll say one thing for it. It keeps us busy (and not in a good way)

--
Gail Shaw
SQL Server MVP
Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2008-07-07 : 06:01:06
I don't understand. What is the question? The query above seems to be fine.
Go to Top of Page
   

- Advertisement -