Replace the * with the @ symbol, except the one in select *.
P
create proc proc_name
*dbname
as
begin
declare *commandvar nvarchar(4000)
declare *exists integer
select *commandvar = 'select *exists = case when exists (select * from ' + *dbname + '.dbo.db_version where current_version = ''1.0.1.1'') then 1 else 0 end'
execute dbo.sp_executesql *comnnandvar, N'*exists integer output', *exists output
return *exists
end
go
-----Original Message-----
From: shrikant
[mailto:mssqldba-ezmlmshield-x13808740.[Email address protected]
Sent: Thursday, June 30, 2005 7:45 AM
To: LazyDBA Discussion
Subject: Query a table in any database
Hi gurus,
I am trying to create a stored proc, which accepts a database name as
parameter.
This is then supposed to query a table on a field
(db_version.current_version) in "that database", and check if the value in
that field is = '1.0.1.1'
If that matches , stored proc should return '1'. In all other cases, it
should return '0' (other cases could be , no table/field with name
db_version.current_version present in the specified database, table
present but field not present etc) .
I have tried using INFORMATION_SCHEMA.COLUMNS, but not getting a good
query to achieve the above result.
I appreciate any help given ! .. Thanks in advance.
regds,
Shrikant
Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you
---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
Website : http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html
MS Sql Server LazyDBA home page