SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 need help with question
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

adiboy0420
Starting Member

USA
10 Posts

Posted - 07/16/2012 :  23:52:38  Show Profile  Reply with Quote
please help

i have a query so far is below, i am later going to turn this into a fuction and have a input parameter fromt he user with either as T or V.

my code is :

declare @x varchar (10)

set @x = 'V'

if @x='V'

begin --1

select name
from sys.views
where is_ms_shipped = 0
end --1
else
Begin --2
if @x = 'T'

begin--3
select name

from sys.tables
where is_ms_shipped = 0
end--3


end

-- which works fine and gives me back

vAdditionalContactInfo
vEmployee
vEmployeeDepartment
vEmployeeDepartmentHistory
vIndividualCustomer
vIndividualDemographics
vJobCandidate
etc
ect

but i need the answer to be

vAdditionalContactInfo;vEmployee;vEmployeeDepartment;vIndividualCustomer;vIndividualDemographics;vJobCandidate;ect;ect

--------------------- question-------

so i am trying to build a table line fuction, so how do i do that??

if you can help me with the coding part i can just work on creating it as a table line function.... please give me clues .....

lionofdezert
Aged Yak Warrior

Pakistan
864 Posts

Posted - 07/17/2012 :  02:09:52  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
declare @x varchar (10)

set @x = 'V'

if @x='V'

begin --1

select SUBSTRING(( SELECT '; ' + name
from sys.views
where is_ms_shipped = 0
FOR
XML PATH('')
), 2, 8000) AS view_name
end --1
else
Begin --2
if @x = 'T'

begin--3


select SUBSTRING(( SELECT '; ' + name
from sys.tables
where is_ms_shipped = 0
FOR
XML PATH('')
), 2, 8000) AS table_name

end--3

end
------------




--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48097 Posts

Posted - 07/17/2012 :  10:22:07  Show Profile  Reply with Quote
isnt it enough to use INFORMATION_SCHEMA.TABLES which contains both tables and views

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lionofdezert
Aged Yak Warrior

Pakistan
864 Posts

Posted - 07/18/2012 :  05:19:49  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
visakh you are just a genious ;)

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48097 Posts

Posted - 07/18/2012 :  10:32:42  Show Profile  Reply with Quote
quote:
Originally posted by lionofdezert

visakh you are just a genious ;)

--------------------------
http://connectsql.blogspot.com/



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000