Identifying The Tables Used In Procedure Or Function
Sep 22, 2006MAH writes "Hi,
How to identify the all tables in stored procedure and function"
MAH writes "Hi,
How to identify the all tables in stored procedure and function"
I have inherited support for a database with many used tables. Thereisn't any documentation on what is used or dead. I was hoping to runtraces and capture the objectid but the property doesn't work thatway.Any good ideas would be appreciated.
View 3 Replies View RelatedCan any one recommend an approach for identifying the frequently accessed tables and files in a SQL/Server application? Particularly, if the database is stored on raw partitions instead of FAT or NTFS. Thanks.
View 3 Replies View RelatedWhen distributing a SQL Server database to customers we need to be able to
tell which version of a stored procedure is currently installed on the user's machine. Does 6.5 or 7.0 provide any way to monitor versions like this?
I have a report based on our product names that consists of two parts.Both insert data into a temporary table.1. A single grouped set of results based on all products2. Multiple tables based on individual product names.I am getting data by calling the same stored procedure multipletimes... for the single set of data I use "product like '%'"To get the data for individual products, I am using a cursor to parsethe product list.It's working great except that I have no idea how to identify theresults short of including a column with the product name. While thatis fine, I'm wondering if there is something that is like a header ortitle that I could insert prior to generating the data that would looka little tighter.Thanks in advance-DanielleJoin Bytes!
View 3 Replies View Related Hi everybody, I am having trouble how to fixed this code. I am trying to supply the parameterinside a stored procedure with a value, and displays error message shown below. If I did not supply the parameter with a value, it works. How to fix this?Error Message:Procedure or function <stored proc name> has too many arguments specified.Thanks,den2005
Stored procedure:
Alter PROCEDURE [dbo].[sp_GetIdeaByCategory]
@CatId <span class="kwd">int</span> = 0
AS
BEGIN
SET NOCOUNT ON;
Select I.*, C.*, U.* From Idea I inner join IdeaCategory C on I.CategoryID = C.IdeaCategoryID inner join Users U on I.UserID = U.UserID Where I.CategoryID = @CatId Order By LastModifiedDate Desc
End
oDataSource.ConnectionString = constr;
oDataSource.SelectCommand = storedProc;<span class="cmt">//storedproc - sp_GetIdeaByCategory</span>
oDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
oDataSource.SelectParameters.Add(<span class="st">"@CatId"</span>, catId);
gdvCategories.DataSourceID = oDataSource.ID;
gdvCategories.DataBind(); <<--- Error occured here
Can someone help me with this issue? I am trying to update a record using a sp. The db table has an identity column. I seem to have set up everything correctly for Gridview and SqlDataSource but have no clue where my additional, phanton arguments are being generated. If I specify a custom statement rather than the stored procedure in the Data Source configuration wizard I have no problem. But if I use a stored procedure I keep getting the error "Procedure or function <sp name> has too many arguments specified." But thing is, I didn't specify too many parameters, I specified exactly the number of parameters there are. I read through some posts and saw that the gridview datakey fields are automatically passed as parameters, but when I eliminate the ID parameter from the sp, from the SqlDataSource parameters list, or from both (ID is the datakey field for the gridview) and pray that .net somehow knows which record to update -- I still get the error. I'd like a simple solution, please, as I'm really new to this. What is wrong with this picture? Thank you very much for any light you can shed on this.
View 9 Replies View RelatedCan anybody know ,how can we add builtin functions(ROW_NUMBER()) of Sql Server 2005 into database library.
I get this error when i used into storeprocedure :
ROW_NUMBER() function is not recognized in store procedure.
i used MS SQL SERVER 2005 , so i think "ROW_FUNCTION()" is not in MS SQL SERVER 2005 database library.
I need to add that function into MS SQL SERVER 2005 database library.
Can anbody know how we can add that function into MS SQL SERVER 2005 database library?
Has anyone encountered this before?
Procedure or Function 'stored procedure name' expects parameter '@parameter', which was not supplied.
It seems that my code is not passing the parameter to the stored procedure.
When I click this hyperlink:
<asp:HyperLink
ID="HyperLink1"
Runat="server"
NavigateUrl='<%# "../Division.aspx?CountryID=" + Eval("CountryID")%>'
Text='<%# Eval("Name") %>'
ToolTip='<%# Eval("Description") %>'
CssClass='<%# Eval("CountryID").ToString() == Request.QueryString["CountryID"] ? "CountrySelected" : "CountryUnselected" %>'>
</asp:HyperLink>
it is suppose to get the country name and description, based on the country id.
I am passing the country id like this.
protected void Page_Load(object sender, EventArgs e)
{
PopulateControls();
}
private void PopulateControls()
{
string countryId = Request.QueryString["CountryID"];
if (countryId != null)
{
CountryDetails cd = DivisionAccess.GetCountryDetails(countryId);
divisionNameLabel.Text = cd.Name;
divisionDescriptionLabel.Text = cd.Description;
}
}
To my app code like this:
public struct CountryDetails
{
public string Name;
public string Description;
}
public static class DivisionAccess
{
static DivisionAccess()
public static DataTable GetCountry()
{
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandText = "GetCountry";
return GenericDataAccess.ExecuteSelectCommand(comm);
}
public static CountryDetails GetCountryDetails(string cId)
{
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandText = "GetCountryDetails";
DbParameter param = comm.CreateParameter();
param.ParameterName = "@CountryID";
param.Value = 2;
param.DbType = DbType.Int32;
comm.Parameters.Add(param);
DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
CountryDetails details = new CountryDetails();
if (table.Rows.Count > 0)
{
details.Name = table.Rows[0]["Name"].ToString();
details.Description = table.Rows[0]["Description"].ToString();
}
return details;
}
As you can see I have two stored procedures I am calling, one does not have a parameter and the other does. The getcountry stored procedure returns the list of countries in a menu that I can click to see the details of that country. That is where my problem is when I click the country name I get
Procedure or Function 'GetCountryDetails' expects parameter '@CountryID', which was not supplied
Someone please help!
Thanks Nickdel68
Hi,
I am in a dilemma. The scenario is:
I have a table with a long stream (1000 bytes non-fixed length)with delimited words. I need to get the words out in a separate table and do it fast.
Ideally a cursor is the solution but having added things like User defined functions and Table data types, I was tempted to use these. The master table having about 15 million rows with upto 200 delimited words in each row on an average, the cursor would have taken weeks.
I got very close. I developed the function that will accept a stream of words and return table data that could be inserted into the second table where I wanted it to be. It worked great with a constant string(see the statement below)
select *
from FnGetWords('aba ba ba baba ba baba bab ababa')
The only problem is now I need to pass the stream from another table:
something like this
select *
from FnGetWords(stream), Mastertable
I know a functioncan be called in a select statement but what I need to figure out is how I can use that in the From clause or pass the stream to it without using the cursor.
Any immediate help will be highly appreciated..
Thanks tons in anticipation,
Christina
hey everyone.
I'm new too SQL and have been having a little trouble trying to make an invoice report.
I have a database for a fake shop and want to pull out 5 colums of information from two different tables and only display the most recent case(latest date).
The 5 pieces of information i want displayed are called:
Product .ProductNo, Product .Description, Product .UnitPrice, Sale_Line.Qty, Sale_Line.SalePrice
...and saledate is stored in Invoice.SaleDate
My current attempts doesn't work(or even run) but i have included it below:
SELECT Invoice.SaleDate, Product .ProductNo, Product .Description, Product .UnitPrice, Sale_Line.Qty, Sale_Line.SalePrice
FROM Invoice INNER JOIN
Sale_Line ON Invoice.InvoiceNo = Sale_Line.InvoiceNo INNER JOIN
Product ON Sale_Line.ProductNo = Product .ProductNo
(SELECT max(SaleDate) AS maxdate
FROM Invoice) maxresults
WHERE Invoice.SaleDate = maxresults.maxdate;
....Any help with this problem would be much appreciated!
thanks
Hi,
I am rather new to SQL 2005 and I am currently facing a problem when I attempt to sum the income and expenses which requires joining 2 tables. My sql string that is currently having a problem is listed below:
I USED THIS STATEMENT:
SELECT TblIncome.Recieve, SUM(TblIncome.Amount) AS TotalIncome, SUM(TblExpenses.Amount) AS TotalExpenses
FROM tblincome,tblexoenses
WHERE tblincome.recieve=tblexpenses.paymentto
GROUP BY TblIncome.Recieve
AND I ALSO USED THIS STATEMENT:
SELECT TblIncome.Recieve, SUM(TblIncome.Amount) AS TotalIncome, SUM(TblExpenses.Amount) AS TotalExpenses
FROM TblIncome INNER JOIN
TblExpenses ON TblIncome.Recieve = TblExpenses.paymentTo
GROUP BY TblIncome.Recieve
The problem that occurs is it sums and multiplies the number of records in the second table. For example,
TblIncome:
Recieve Amount
John 5
John 2
David 1
TblExpenses:
PaymentTo Amount
John 3
David 2
Currently, it is showing me as follows:
Recieve TotalIncome TotalExpenses
John 7 6
David 1 2
The problem is in total expenses, it multiplies the number of records in TblIncome.
Also, if TblExpenses has more than 1 record, it multiplies the total income with the number of records.
Does anyone know how to solve this problem? Thanks
--
http://blog.slickw0rm.net
I have two tables that contain product SKUs (12-character strings):
Table 1Product IdSKU...
Table 2ProductVariantIdSKU...
I need to find the MAX (i.e., last used) SKU that exists in either table. I did write two sps, one for each table that I can compare in code and use the larger (latest) one but I am not that facile with JOINS, etc., so I can't figure how how to create a single sp to return the value I am looking for--although I assume this must not only be possible but trivial to more experienced SQLers.
Thanks!
Duncan
I have data like this in a two column temporary table -ID Age23586 323586 323586 223586 223586 123586 123586 123586 123586 1I need to create a temporary table that look like this:ID Age1 Age2 Age3 Age423586 5 2 2 0However, what I get is this:23586 5 NULL NULL NULL23586 NULL 2 NULL NULL23586 NULL NULL 2 NULLHere is the query that I am using...select managed_object_id, (select count(Age) where Age = 1) As Age1,(select count(Age) where Age = 2) as Age2,(select count(Age) where Age = 3) as Age3,(select count(Age) where Age = 4) as Age4into #enhancementCount from #enhancementsgroup by managed_object_id, AgeWhere's my mistake?Thanks-Danielle
View 4 Replies View RelatedA have a number of similar tables and what I want to do is to get the count of records grouped by day of week. All tables have date as an indexed unique column but the actual timestamps differs and have no relation. For one table I use this simple querry:
Select DatePart(dw,dato) AS DOW, Count(dato) AS NOR FROM AWP2
where dato > '2006-08-11'
Group By DatePart(dw,dato)
A typical result:
DOW NOR
3 8934
6 22397
7 23328
1 23401
4 1938
2 24399
5 1112
Trying to join two or more tables in all sorts of variants of this:
Select datePart(dw,a1.dato) AS DOW1,Count(a1.dato) [Amount 1],
datePart(dw,a2.dato) AS DOW2, Count(a2.dato) [Amount 2]
FROM AWP1 A1 Inner Join AWP2 A2 on datePart(dw,a1.dato) = datePart(dw,a2.dato)
Where a1.dato > '2006-08-11' AND a2.dato > '2006-08-11'
Group By datePart(dw,a1.dato), datePart(dw,a2.dato)
Here I get this as a typical result:
DOW1 Amount 1 DOW2 Amount 2
6 332953802 6 332953802
3 42248886 3 42248886
1 330281714 1 330281714
7 335759904 7 335759904
4 1232568 4 1232568
5 210168 5 210168
2 366985359 2 366985359
Where the numbers are way off.
Any suggestions?
I have created the following view:
Create view vwOrderItemTotal2
AS
SELECT ItemName, fkMenuItemID, Sum(Quantity) as [SumOfMenuITems] FROM OrderItems GROUP BY fkMenuItemId, ItemName
When I present my data in a GridView, it works fine. For example, several orders for milk are returned as a summary quantity of 26 gallons in a single row of the GridView like this:
26 Milk
Now I need to filter my data by OrderDate and Zipcode. I created this new view:
Create view vwOrderItemTotal5
AS
SELECT Orders.Zipcode, Orders.OrderDate, OrderItems.ItemName, OrderItems.fkMenuItemID, Sum(Quantity) as [SumOfMenuITems]
FROM Orders INNER JOIN OrderItems
ON Orders.OrderID = OrderItems.fkOrderID
GROUP BY fkMenuItemId, ItemName, Zipcode, OrderDate
When I present my data in a Gridview using the new view I get a GridView with multiple rows for milk where each order has its own row like this:
1 Milk
5 Milk
6 Milk
6 Milk
3 Milk
1 Milk
4 Milk
But I want the data presentation in one row for each ItemName (e.g. Milk) as with my first view. Can I adjust my new view to achieve this, or should I stick with my first view (vwOrderItemTotal2) and adjust the Select Command in my SqlDataSource (hasn’t worked yet).
I think that what I want is for the returned data to be grouped by fkMenuItemId only, but the sql server admin won’t let me create a view without including the other fields in the Group By clause. Thanks for any help provided in solving this.
This is so complicated (for me) because I usually only work with single table and simple queries (SELECT, INSERT, UPDATE), but now I am in a situation where I am stuck.
What I am trying to archive is that: when a project manager logged-into his/her account, a grid-view will show a quick overview for all of his/her projects (id, created date, name and how many files are in pending) like below picture:
3 tables will be involved are:
Sample data for manager_id = 11
I tried this query but it not worked, it seems to display all columns right but the COUNT pending files column (assume the manager_id = 11)
SELECT COUNT(file_id) as 'Pending files', projects.project_id, projects.project_name, projects.status, projects.start_date
FROM ((project_manager
INNER JOIN files
ON project_manager.mag_id = files.manager_id AND project_manager.mag_id = 11 AND file_status = 'Pending')
INNER JOIN projects
ON projects.project_id = project_manager.project_id)
GROUP BY projects.project_id, projects.project_name, projects.status, projects.start_date
ORDER BY projects.status, projects.start_date DESC
result of this query:
Hiya,Is there really no way to use temporary tables from within a UDF? Ilike UDFs because I can use them like a table -- e.g., SELECT row1,row2 from MyFunc('abc')
View 1 Replies View RelatedTrying to get a handle on how to attack this problem of adding a new record in a table that has 2 joins to access (user) and associate with a grandparent table (hotel).
There is also a date condition with a separate table (contracts) in order to start the operation.
Select from Contracts where TermBegin and TermEnd <> today
For each contract hotel{
#Do they already have user?
Match User.ID + Organization.ID + Hotel.ID
If not{
Create Person
}
I'm not sure how to return the negative results of the 3 table join of User.Id + Organization.ID + Hotel.Id
Thanks for any tips/iedas
I used a function to create dataset as below:
Public Function GetSQLDataSet(ByVal SQL As String) As DataSet
......
MyConnection = New SqlConnection(MyConnectionString)
MyCommand = New SqlCommand(SQL, MyConnection)
MyDataSet = New DataSet
MySQLDataAdapter = New SqlDataAdapter(MyCommand)
MySQLDataAdapter.Fill(MyDataSet)
......
End function
It works fine.
How to code a function to return a dataset in which there are two tables and relationship?
Hi,I m searching for some Script / Function ... to find difference in datab/w 2 similar tables (exactly same fields structure) in sql 2000.plz update me asap !thanks in advance !
View 2 Replies View RelatedI have these 3 tables in a database for printed chamber music works:
Table INSTRUMENTS: List of musical instruments
Column ID -- int, primary key
Column sInstrument -- string
Table PTRS_INSTRUMENTATION:
Column ID -- int, primary key
Column lInstrument -- int, points to a row in table INSTRUMENTS via ID
Column lMainItem -- int, points to a row in table MAINITEMS via ID
Column lInstrSeqNum -- int, sequential number of like instruments within one Main Item
Table MAINITEMS: List of chamber music works
Column ID -- int, primary key
Column sItem -- string
Each chamber music work (Main Item) requires an ensemble of musicians playing several instruments. Some of them may be the same, such as 2 violins. A classical quartet, for instance, consist of 2 violins, 1 viola and 1 cello. I am concerned here only with one of the instruments (although it may occur several times).
I want to extract a list of Main Items where the instrument is given (e.g., 'violin'),
And the maximum of PTRS_INSTRUMENTATION.lInstrSeqNum is a given number (e.g., 2).
Hello,
I have recently started working on a OLAP application. The database is around 35 gig, with over half of that space being taken by the indexes. What has happened is previous developers have added indexes to attempt to improve the performance of a select statement (for reporting). Some of the indexes work, but many do not.
I would like to drop the ineffective indices. What I would like is a way to find if indexes are being used, preferably by object name. Is there a third party vendor that can monitor objects and how much they are used? Is there another way to do this using SQL?
Thanks in advance,
Jim
Hi,
I need to delete ONLY the duplicate rows from a table..Can anyone suggest me a way to do that thing..i used the query..
"Delete from <TableName> where SlNo IN ( Select SlNo from <TableName> group
by SlNO having Count(*) > 1)"
The resultant is all the original rows also getting deleted with the duplicates..anyone please help me out..
Thank you in advance
Rani
How can get an object's dependencies in SQL Server. For example it I have written a procedure which accesses some tables inside it then the procedure is said to be dependent on that table. Or one procedure might call another procedure and hence dependent.
Can I know an object's dependent objects from any system table. I think Oracle has a table USER_DEPENDENCIES which provides this info (I may be wrong :-().
Can anyone help ?
Hi,can anybody tell me how to identify all the databases from all the servers that are being accessed by a particular group
View 11 Replies View RelatedHi
Is there any way to Identify a Deadlock using the Enterprise Manager.
Someone told me that the Red Icon on the Lock/Process ID (Spid) mean a Dealock ... is that True ???
Hi,
Can we define a non-identifying relationship between 2 tables in MS SQL? If yes, what will be the syntax based on what I have:
ALTER TABLE PM_VARIABLE_BIN
ADD CONSTRAINT PM_VarCoef_PM_VarBin_FK1 FOREIGN KEY (MODEL_ID,VERSION,VAR_ID) REFERENCES PM_VARIABLE_COEFFICIENT(MODEL_ID,VERSION,VAR_ID)
go
Some columns in transaction tables are "mandatory fields" on the dataentry screens, and as a result tend to accumulate junk entries, wherethe user puts something, anything, in the window in order to get theGUI to accept the screen. This filler isn't as elaborate as LoremIpsum, but more likely characters from adjacent keys on the second rowof the keyboard, like "lkjkljl". This non-data gets in the way ofapplications that use the data. I wonder if there is a way torecognize and ignore this stuff -- I would assume it's a well-knownproblem, but I haven't found any literature on it. Any pointerswelcome. And sorry if this is off-topic for a DB group.Thanks,Jim Geissman
View 2 Replies View RelatedHi AllThe problem:!!I want to create a temp table which is common between different usersso that each user could select his rows and print them withoutprinting others selection.All clients use the same connection string.Is there a way to identify users?I think it's possible to delete rows of a user when he logs out theprogram.Do I think right?thanks very muchHafez
View 1 Replies View RelatedHas previous work been done on this? Is their a library one can download? Here's the problem. In an aricle a person or author may make a statement about a subject or a person. I am making a database on this.
For example, here in Israel, PM Olmert may make a statement on the teacher's strike or on Abu Mazen. The article may say, speaking of Mazen, Olmert said such and such. PM Olmert said, "xxxxxxx......." with the previous material making it clear whathe was speaking of.
Right now I have ugly code. Is there a neat way of doing this?
If this is the wrong forum, can somebody direct me to the right forum?
Thanks.
Dennist
Have a table showing info like:
Region_ID
Branch_ID
Customer_ID
Transaction_ID
In this regard need to create a view to reflect the info in the order
Region_ID (Ascending)
Branch_ID (Asc)
Customer_ID (Asc)
Transaction_ID (Asc)
But, at the same time, also want to include two additional columns identifying or even inserting 1's against each of the first Customer_ID considering the first two columns, and the second one on the single column itself?In other words consider the following sample, how to add 1 to the last two columns where either the Customer appears for the first time in context with the Region and Branch Fields or to be appearing on it's own for the first time:
Region
Branch
Customer
Transaction
Required_A
Required_B
[code]....
Im getting this error when looping through a gridview. Im trying to save each row into the database. The weird thing is that it saves the first row, but errors out on the second.If I only add one item to the gridview, it works. The second row is screwing it up somehow. Any ideas? ------------------------------------------------------------------------------------------------------------------------------------------------------------------Some of my code to get an idea of how im doing it:(This
is for a shopping cart. It displays the products in the shopping cart.
If the order is approved by the CC processing company, each product
entry is saved in the DB. The gridview is being populated by my
ShoppingCart Profile Object.) SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["rdevie"].ConnectionString);
SqlCommand objCmd = new SqlCommand("InsertOrderDetails", objConn);
objCmd.CommandType = CommandType.StoredProcedure;
objConn.Open();
foreach (GridViewRow row in gvOrderDetails.Rows)
{
objCmd.Parameters.Add("@idOrder", SqlDbType.Int).Value = orderNum;
objCmd.Parameters.Add("@fldName", SqlDbType.NVarChar).Value = ((Label)row.FindControl("lblName")).Text;
objCmd.Parameters.Add("@fldUnitPrice", SqlDbType.Money).Value = ((Label)row.FindControl("lblUnitPrice")).Text;
objCmd.Parameters.Add("@fldQuantity", SqlDbType.Int).Value = Convert.ToInt32(((Label)row.FindControl("lblQuantity")).Text);
if (!String.IsNullOrEmpty(((Label)row.FindControl("lblSku")).Text))
objCmd.Parameters.Add("@fldSku", SqlDbType.NVarChar).Value = ((Label)row.FindControl("lblSku")).Text;
else
objCmd.Parameters.Add("@fldSku", SqlDbType.NVarChar).Value = DBNull.Value;
objCmd.Parameters.Add("@fldSize", SqlDbType.NVarChar).Value = ((Label)row.FindControl("lblSize")).Text;
objCmd.Parameters.Add("@fldLogo", SqlDbType.NVarChar).Value = ((Label)row.FindControl("lblLogo")).Text;
objCmd.Parameters.Add("@fldPlacement", SqlDbType.NVarChar).Value = ((Label)row.FindControl("lblPlacement")).Text;
objCmd.Parameters.Add("@fldColor", SqlDbType.NVarChar).Value = ((Label)row.FindControl("lblColor")).Text;
objCmd.ExecuteNonQuery();
}
objCmd.Dispose();
objConn.Close();
objConn.Dispose();