Alright just starting out in ASP.NET and it's making my head spin, but I think I'm getting it.
My schema in brief : Images, Categories, and a table in the middle so we can have a many-to-many relationship between images and categories. My issue is searching. I can search by keyword, and limit it to categories. So, in pseudo sql..
SELECT ... WHERE keyword LIKE '%test%' and category_id in (1,5,20,66);
I made a variable for the keyword no problem. But how can I get this dynamic list? Or, is there another way about going this problem?
I have been given the task of adding an option to "Search Top Stories" on an existing full text search we already had. I thought this would be easy, just another content type to throw in, but regretfully top stories are calculated on this site on the fly it seems.
The original search (made back in 2003 I think) did the full text search with various cases for various options. I don't understand the full relevance of all of them but its not really necessary. I thought an easy solution would be to get the IDs of top stories and run the same search and include only if the ID is in the top stories list (how disgustingly inefficient, but I really don't have time to rebuild it all - especially when I dont know where else this SP is used). I get an error in the query analyser: Server: Msg 156, Level 15, State 1, Line 87 Incorrect syntax near the keyword 'WHERE'.
For the life of me I can't figure out what its complaining about.
This is the SQL for the search on the top stories only (so 2nd half of the union):
SELECT DISTINCT TOP 100 PERCENT S.SearchID, S.TypeID, S.IndexID, CT.Rank, S.ArchiveDate, CASE @Group WHEN 1 THEN S.TypeID END, CASE @OrderType WHEN 1 THEN ArchiveDate END as a, CASE @OrderType WHEN 2 THEN ArchiveDate END as b, CASE @OrderType WHEN 3 THEN Rank END as c
FROMTT_Articles A INNER JOINTT_XChannelArticle ON A.Article_ID = TT_XChannelArticle.Article_ID RIGHT OUTER JOINTT_SearchIndex S INNER JOINContainsTable(TT_SearchIndex,Content,@SearchTerms) CT ON S.SearchID=CT.[Key] LEFT OUTER JOIN TT_XChannelArticle XA ON S.IndexID=XA.Article_ID AND S.TypeID IN (2,3,4,5) AND XA.Channel_ID IN (SELECT * FROM @ChannelTable) LEFT OUTER JOIN TT_PressReleases PR ON S.IndexID=PR.Press_ID AND S.TypeID=1 AND PR.Channel_ID IN (SELECT * FROM @ChannelTable)
WHERE A.ArticleID IN ( SELECT DISTINCT TT_Articles.Article_ID FROM TT_Articles INNER JOIN TT_XChannelArticle ON TT_Articles.Article_ID = TT_XChannelArticle.Article_ID WHERE (TT_Articles.ArticleDate <= GETDATE()) AND (TT_Articles.Approved = 1) AND (TT_Articles.Type = 2) AND (TT_XChannelArticle.Channel_ID IN (SELECT * FROM @ContentTable)))
If you would like I can post the original stored procedure.
@ChannelTable and @ContentTable are comma-delimited lists that have been turned into single field tables.
Whoa what a post, thanks for any help you can give guys. I know the design can really be improved, and I'm sure we will do a rebuild next year.
Dear All, I want to practise writing complex T sql queries in SQl Server 2005 which involve several joins, sub-queries in a single query. This kind of queries are commonly required in Reporting scenarios where a single report may have to be prepared from 2,3 or more tables. Presently I am able to write queries of moderate complexity. Therefore I am looking for web tutorials, books which contains some solved examples as well as some Unsolved ones. The Unsolved ones should have the answers given so that one comes to know if he makes a mistake. The web tutorials can be from paid sites as well. If any of you have a good collection of such queries then pls be kind enough to send it to me.I will give my email id for the purpose. If anybody can help in some other way pls let me know. Your help will be highly appreciated. Thanks .
i am getting to trip with SQL Server and i find it is quite interesting. please send me complex TSQL queries which would help me to test my SQL server expertise. do let me know what are the URLs where i can find complex TSQL Queries i appreciate pointers in right direction
hi thereanyone had an idea to join following 2 queries to 1????----- QUERY 1 ---------------------------------------------SELECT TMS_CaseF_2.Name AS TCDomain_0,TMS_CaseF_3.Name AS TCDomain_1,TMS.CaseF.Name AS TCFolder_2,TMS_CaseF_1.Name AS TCFolder_3,TMS.TestCase.Name AS TCName_4,TMS_TestCase_1.Name AS TCName_5,TMS.LogFolder.Name AS PlannedLogFolder_6,TMS.Log.Name AS PlannedLog_7,TMS.CaseResult.RecordedCaseName AS TCRecordedName_8,TMS.TestPlan.Name AS Plan_9FROM((((((((((TMS.Build INNER JOIN TMS.LogFolder ON TMS.Build.UID =TMS.LogFolder.Build)INNER JOIN TMS.Log ON TMS.LogFolder.UID = TMS.Log.LogFolder)INNER JOIN TMS.CaseResult ON TMS.Log.UID = TMS.CaseResult.Log)INNER JOIN TMS.TestCase ON TMS.CaseResult.TestCase =TMS.TestCase.UID)LEFT JOIN TMS.CaseF ON TMS.TestCase.Parent = TMS.CaseF.UID)LEFT JOIN TMS.TestCase AS TMS_TestCase_1 ON TMS.TestCase.Parent =TMS_TestCase_1.UID)LEFT JOIN TMS.CaseF AS TMS_CaseF_1 ON TMS_TestCase_1.Parent =TMS_CaseF_1.UID)LEFT JOIN TMS.CaseF AS TMS_CaseF_2 ON TMS_CaseF_1.Parent =TMS_CaseF_2.UID)LEFT JOIN TMS.CaseF AS TMS_CaseF_3 ON TMS.CaseF.Parent =TMS_CaseF_3.UID)INNER JOIN TMS.TestPlan ON TMS.TestCase.TestPlan = TMS.TestPlan.UID)WHERE (((TMS.LogFolder.Name) Like 'TR1%')AND ((TMS.Build.Name)='Planning_VD10A'))ORDER BY TMS.CaseF.Name,TMS_CaseF_1.Name,TMS.TestCase.Name,TMS_TestCase_1.Name;------------------------------------------------------------------ QUERY 2 ---------------------------------------------SELECT TMS.CaseResult.RecordedCaseNameFROM ((TMS.Build INNER JOIN TMS.LogFolder ON TMS.Build.UID =TMS.LogFolder.Build)INNER JOIN TMS.Log ON TMS.LogFolder.UID = TMS.Log.LogFolder)INNER JOIN TMS.CaseResult ON TMS.Log.UID = TMS.CaseResult.LogWHERE (((TMS.LogFolder.Name) Like 'VD%')AND ((TMS.Build.Name)='VD10A IT_APP'));
Hello Friends. I have few doubts regarding the use of Sqldatasource server control. Is the control flexible enough to achieve these things:- 1.To perform complex queries using Sqldatasource. For eg:- using JOIN to retrieve/insert data from/into multiple tables.2.Performing cascading dropdownlist using sql database as datasource.3.Performing For loops eg:-populating the multiple items into the listbox from sqldatasource. and retrieving them at once.4.use ajax update panel.etc.any example/sample on how to achieve these task?thanks.jack.
I'm dealing with queries that manages a lot of data consolidation and I'm having to repeat large blocks of code to get the desired result. I'm wondering if that is any way to make it simple.
My queries looks like this:
Code BlockSELECT (A + B) AS C, (D + E) AS F, (G + H) AS I, (A + B) * (D + E) AS total1, (D + E) * (G + H) AS total2, (A + B) * (G + H) AS total3, (A + B) * (D + E) * (G + H) AS total FROM table
Can I somehow declare each part of the expression and make it something like this?
Code Block SELECT (A + B) AS C, (D + E) AS F, (G + H) AS I, C * F AS total1, F * I AS total2, C * I AS total3, C * F * I AS total FROM table
Maybe it seems silly, but each sub-expression, on the real life, includes a lot of CASEs and aggragate functions and my codes are getting complex and confuse.
Since I have lots of code pieces that I repeat more than once, I would like to make it simpler.
Any recommendations for good advanced t-sql books/articles? I find myself involved with writing increasingly more complex queries and after spending a few hours on some, and then searching on this site for potential answers/help, I am wondering if there might be some good books on creating more advanced/complex t-sql for real world scenarios.
I am not very good in queries. Could you please suggest me some web site/Tutorial/Artical where i can get Study Material for complex and real life queries. I know the syntexes, I just need to practice queries to enhance my skills
I have web forms with about 10-15 optional search parameters (fields) for a give table. Each item (textbox) in the form is treated as an AND condition.
Right now I build complex WHERE clauses based on wheather data is present in a textbox and AND each one in the clause. Also, if a particular field is "match any word", i get a ANDed set of OR's. As you can imagine, the WHERE clause gets quite large.
I build clauses like this (i.e., 4 fields shown):
SELECT * from tableName WHERE (aaa like '%data') AND (bbb = 'data') AND (ccc like 'data%') AND ( (xxx like '%data') OR (yyy like '%data%') )
My question is, are stored procedures better for building such dynamic SQL clauses? I may have one field or all fifteen. I've written generic code for building the clauses, but I don't know much about stored procedures and am wondering if I'm making this more difficult on myself.
I typically use DataAdapters and Datasets from the toolbox when connecting to a SQL database. Since switching to VS 2005, I am not able to find (or add) these items to the tool box for web site development. Any ideas on how I can get them back? Or is there a better alternative to retrieving the data so I can process it? Any help or suggestions would be appreciated.
Can anyone advise me on how to view the contents of a dataset in VS dotnet 2003..
I had filled a dataset from a query...But i don know what happens after filling the qry results.It might be helpful if someone tells me to view the contents of the dataset
I have become a big fan of the datasets in Visual Studio 2005. I usually create the SQL for each method in the table adapter; however, I am wondering if there is any 'built-in' functions in the C files for sql injection prevention? I have read that using stored procedures is a good method for prevention. Should I be using SP rather than SQL within my methods in the data table?
Is there any possibility of combining data from two datasets to a single report item. If there is any thing that we can do, can any one please tell me what to do, so that my problem will be solved.
I have a table which has over 450,000 records in it, I have now split this into 4 so each table has around 100,000 records in it but I'm still having the problem of the data being returned really slowly.
What I need to do to this data is group it by a code and show the total for each code for every month of the year (this is currently based on one column and selecting the data accordingly). I have created views and put some indexes onto my table but the results are still being returned slowly. Does anyone have any suggestions of how I can speed this up?
I have a report with four different datasets that slice certain record by different days of the week. I can do the individual summing for each dataset by putting a , "datasetname" at in the expression. I also have 4 matrixes in the report that are grouped on certain transactions within each timeslice. My problem is that if I use the dataset name in the fields, the groups get ignored. Do I have to put the dataset name in each group expression? for example, here is my group expression...
Hello all, I have a report with a table and a chart. It uses dataset1 as the data source. All works fine. I create a new dataset called dataset2. The queries are exactly the same. The only differences between the 2 datasets is the database server and the fact that one of the columns is a smallint (in dataset2) and an int(in Dataset1) I change the datasetName property of both the table and the chart to use dataset2. When I run the report I get a conversion error stating that there was an overflow of int2 while using dataset1. I have verified the report is not using dataset1 anywhere. If I delete dataset1 and run the report the error goes away. If I add it back, I get the error again. Why is the report looking at dataset1 if it is not referenced at all in the report? Does SQL RS cache the datasets and verify each when it compiles?
If I have a dataset that has ID and CODE, and another dataset that has CODE and DESCRIPTION, is it possible to relate these two datasets to one another so I put the ID and Code in columns 1 and 2 and then put the related DESCRIPTION in column 3 on the report table layout? In other words, can you "JOIN" two datasets, or must all that be done in the query and create a unified dataset for the report contents?
Each column right now is a subreport so I can use the object as a parameter to the subreports dataset. Each column needs to have the object as a parameter.
Is there a way I can pass a field from the first dataset as a parameter for the next dataset without using subreports?
I have got two datasets. Some 'normal' rows with state values and an addtional dataset with the translation from state value to plain text (value / text pair).
A table object is attached to the first dataset, but I would like to show the plain text from the second dataset in a group header. So I'd like to do some kind of 'look up in another dataset'.
I wasn't able to find a function that could help me solve this problem. Does anyone has any ideas on this?
i have a report in which i use two datasets the problem is that when i was using only one, there wasn't any scope argument you know, to tell in which dataset i am , because there was only one and all fields and cells in my table returned me the correct values
but as soon as i add the second data set and i drag and drop the datasets fields in my table
Can we use 2 datasets in one report (tabular or chart, either one)?
my report get its data-fed from OLAP database (Cubes) and Oracle tables.
Let say the cube contains the actual sale (all aggregated and query using MDX) and the Oracle table contains the budget value for specific period.
And I am trying to construct a tabular like this:
date item type Revenue Budget Actual (Sale - Budget) Jan calls regular 2000 1800 200 Jan calls super 3000 2500 500 Feb calls new 1000 900 100 Mar calls super 4500 4000 500 ..... and so on
The data for date, item, type and Revenue are available in the OLAP (cubes) and the Budget value is available in Oracle table and we can't afford to transfer the Budget value to the cube.
Is this possible in SSRS? Please let me know if more information needed.
I'm creating a report with SSRS (2005). In that report I have a table, and in that table I need to put fields from two different datasets. But I don't know how to link those both datasets (because if I don't I get a cartezien product)...
is this possible? i need to make a report that accesses two different tables, one for user activity and the other for the number of reports that user has done. the report information is in a different database however so i have to use different datasets. is there a way to use both databases in the same table? all i need is the one field from the reporting one and they can be linked by the user id...
1. A mulitvalued parameter State with WA, SA, QLD, TAS etc
2. A single value parameter of Top n - 10, 20, 40
The user will select the state and the top number to get the top n sellers off that state or a combination off states.
I have a dataset with the following cutdown version off SQL
Declare @TopNo Int
Set @TopNo = @Param_TopNo
Set Rowcount @TopNo
SELECT CreateDate,SaleDate,sales.Consultant, State, Sum(Value) As Winbacks
FROM dbo.tbl_kpi_sales
GROUP BY CreateDate, Consultant, State, SaleDate, Winbacks
ORDER BY Winbacks Desc;
Set RowCount 0
When I execute it and select 'Select all' from the mulitvalued state parameter with a Top N value off 100 the query returns all the top 100, which is correct, however when i select just a single state ie WA it only returns me the records which were in the TOP 100 off all states when it should be filtering it by only the state I choose and returning the 100 records...For some reason it when a single state is selected or a combination off states the dataset is already narrowed down and doesnt reexecute the query for just that state...Can someone suggest how to overcome this, maybe a table filter ?
I am relatively new to MS Reporting and I can€™t figure out how to do something that seems rather simple.
I need to somehow combine two different SQL statements into one dataset. The two different SQL statements are the same, except for the Select list and the Where.
Example,
1st Dataset:
SELECT dbo.claimtable.grpnum_plancode, dbo.plancodetable.plandescription, SUM(dbo.claimtable.charges) AS Charges, SUM(dbo.claimtable.benefitpaid) AS BenefitPaid FROM dbo.claimtable INNER JOIN dbo.plancodetable ON bo.claimtable.grpnum_plancode = dbo.plancodetable.grpnum_plancode WHERE (dbo.plancodetable.plantype = 'Med') AND (dbo.claimtable.paiddate BETWEEN @BeginDate AND @EndDate) AND (dbo.claimtable.paidflag = 'Y') AND (dbo.claimtable.grpnum IN (@GroupNumber)) GROUP BY dbo.claimtable.grpnum_plancode, dbo.plancodetable.plandescription
2nd Dataset:
SELECT dbo.claimtable.grpnum_plancode, dbo.plancodetable.plandescription, COUNT(distinct dbo.claimtable.claimid) AS ClaimCount FROM dbo.claimtable INNER JOIN dbo.plancodetable ON dbo.claimtable.grpnum_plancode = dbo.plancodetable.grpnum_plancode WHERE (dbo.plancodetable.plantype = 'Med') AND (dbo.claimtable.paiddate BETWEEN @BeginDate AND @EndDate) AND (dbo.claimtable.paidflag = 'Y') AND (dbo.claimtable.backoutflag = 'N') AND (dbo.claimtable.grpnum IN (@GroupNumber)) GROUP BY dbo.claimtable.grpnum_plancode, dbo.plancodetable.plandescription
I tried just referring to the different dataset within the report table, but it only provides it at the aggregate level and I need the claimcount at each individual claimtable.grpnum_plancode level.
I tried a union statement, but get a variety of errors.
Hi, I am pretty new to harcore ASP.NET and .NET in general but I know the basics of the language and stuff like that. Basically I used to be a hardcore object pascal Delphi developer doing Windows Applications but have now moved to .NET world. The reason I posted this question here is I couldn't find any other specific place to ask so here it goes. To get me started with good programming source and practices I downloaded the ASP.NET TimeTracker Starter Kit and after some modificaion in connection string (using SQL 2005 Developer edition not the Express one) I have managed to make it work. Things done in there are pretty interesting way by using a delegate to retrieve data and present it using databound controls. As much simple as it sounds I am more of a fan of not using too many databound controls except in dropdown box, list box and stuff like that. So basically I need to develop DataAccessLayer (DAL) in such a way that it's useful for both Windows and Web application. So with my research I found that I should be using DataSets in the DAL because they are serializable and thatz what Web Applications & Services love over using SqlDataReader. Other advantage of using DataSet is to use ForEach syntex over While Loop in SqlDataReaders. So below is some code I extracted from the TimeTracker Starter Kit to get me started. I also noticed that the return result is a list array of certain object, in this case Category. So does it mean that it can be used in frontend using ForEach syntex? How can I convert the code below to use DataSets over SqlDataReader? Private Delegate Sub TGenerateListFromReader(Of T)(ByVal returnData As SqlDataReader, ByRef tempList As List(Of T))
Public Overrides Function GetAllCategories() As List(Of Category) Dim sqlCmd As SqlCommand = New SqlCommand() SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_GETALLCATEGORIES)
Dim categoryList As New List(Of Category)() TExecuteReaderCmd(Of Category)(sqlCmd, AddressOf TGenerateCategoryListFromReader(Of Category), categoryList)
Return categoryList End Function
Public Overrides Function GetCategoryByCategoryId(ByVal Id As Integer) As Category If Id <= DefaultValues.GetCategoryIdMinValue() Then Throw New ArgumentOutOfRangeException("Id") End If
Dim sqlCmd As SqlCommand = New SqlCommand() AddParamToSQLCmd(sqlCmd, "@CategoryId", SqlDbType.Int, 0, ParameterDirection.Input, Id) SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_CATEGORY_GETCATEGORYBYID)
Dim categoryList As New List(Of Category)() TExecuteReaderCmd(Of Category)(sqlCmd, AddressOf TGenerateCategoryListFromReader(Of Category), categoryList)
If categoryList.Count > 0 Then Return categoryList(0) Else Return Nothing End If End Function
Private Sub TGenerateCategoryListFromReader(Of T)(ByVal returnData As SqlDataReader, ByRef categoryList As List(Of Category)) Do While returnData.Read()
Dim actualDuration As Decimal = 0 If Not returnData("CategoryActualDuration") Is DBNull.Value Then actualDuration = Convert.ToDecimal(returnData("CategoryActualDuration")) End If
Dim category As Category = New Category(CStr(returnData("CategoryAbbreviation")), actualDuration, _ CInt(returnData("CategoryId")), CDec(returnData("CategoryEstimateDuration")), CStr(returnData("CategoryName")), _ CInt(returnData("ProjectId"))) categoryList.Add(category) Loop End Sub Hope this makes sense. Sorry if I have posted this in a wrong section..! Cheers,Nirav
I was watching the "To Do List" AJAX video created by Joe Stagner and while watching the video I noticed (in designer) Joe use a Dataset to populate a Gridview and this got me thinking. I have a few gridviews in my app at work that just use SqlDataSources, and they seem to work fine, but is it better to use Datasets ?
i want to make business portal intellegence with sql2000 as my final project but i don't have datasets. i need iventory datasets like northwind or foodmart or middlewest. somebody help me please!!