Using Column Name In 'LIKE' Clause
Hi i want to join two tables basing on like condition of the column values of two tables.
My query is like this:
select
pc_assign_worklist.pxRefObjectInsName AS "pxRefObjectInsName",
pc_assign_worklist.pxUrgencyAssign AS "pxUrgencyAssign",
pc_assign_worklist.pyLabel AS "pyLabel",
pc_assign_worklist.pyAssignmentStatus AS "pyAssignmentStatus",
pc_assign_worklist.pxAssignedOperatorID AS "pxAssignedOperatorID" ,
pc_assign_worklist.pxCreateDateTime AS "pxCreateDateTime" ,
pc_assign_worklist.pxCreateOpName AS "pxCreateOpName",
pc_index_workparty.MemberIdentifier AS "MemberIdentifier",
pc_index_workparty.LastName AS "Last Name",
pc_index_workparty.FirstName AS "First Name",
pc_index_workparty.pxInsName AS "pxInsName"
from
dbo.pc_assign_worklist, dbo.pc_index_workparty
where
pxAssignedOperatorID ='dasxkx1'
AND pc_index_workparty.pzInsKey Like '%'+pc_assign_worklist.pxRefObjectInsName+'%' ORDER BY pxUrgencyAssign DESC
-----------
i want to compare the two columns of two tables using like or contains clause as column1 in table a has value like "hi i am" where as column2 in table2 has value "hi". I need help on how to accomplish this.
View Complete Forum Thread with Replies
Related Forum Messages:
Is It Possible To Re-reference A Column Alias From A Select Clause In Another Column Of The Same Select Clause?
Example, suppose you have these 2 tables(NOTE: My example is totally different, but I'm simply trying to setupthe a simpler version, so excuse the bad design; not the point here)CarsSold {CarsSoldID int (primary key)MonthID intDealershipID intNumberCarsSold int}Dealership {DealershipID int, (primary key)SalesTax decimal}so you may have many delearships selling cars the same month, and youwanted a report to sum up totals of all dealerships per month.select cs.MonthID,sum(cs.NumberCarsSold) as 'TotalCarsSoldInMonth',sum(cs.NumberCarsSold) * d.SalesTax as 'TotalRevenue'from CarsSold csjoin Dealership d on d.DealershipID = cs.DealershipIDgroup by cs.MonthIDMy question is, is there a way to achieve something like this:select cs.MonthID,sum(cs.NumberCarsSold) as 'TotalCarsSoldInMonth',TotalCarsSoldInMonth * d.SalesTax as 'TotalRevenue'from CarsSold csjoin Dealership d on d.DealershipID = cs.DealershipIDgroup by cs.MonthIDNotice the only difference is the 3rd column in the select. Myparticular query is performing some crazy math and the only way I knowof how to get it to work is to copy and past the logic which isgetting out way out of hand...Thanks,Dave
View Replies !
Expression Defined In SELECT Clause Overwrites Column Defined In FROM Clause
2 examples: 1) Rows ordered using textual id rather than numeric id Code Snippet select cast(v.id as nvarchar(2)) id from ( select 1 id union select 2 id union select 11 id ) v order by v.id Result set is ordered as: 1, 11, 2 I expect: 1,2,11 if renamed or removed alias for "cast(v.id as nvarchar(2))" expression then all works fine. 2) SQL server reject query below with next message Server: Msg 169, Level 15, State 3, Line 16 A column has been specified more than once in the order by list. Columns in the order by list must be unique. Code Snippet select cast(v.id as nvarchar(2)) id from ( select 1 id union select 2 id union select 11 id ) v cross join ( select 1 id union select 2 id union select 11 id ) u order by v.id ,u.id Again, if renamed or removed alias for "cast(v.id as nvarchar(2))" expression then all works fine. It reproducible on Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2) and Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86) Feb 9 2007 22:47:07 Copyright (c) 1988-2005 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2) In both cases database collation is SQL_Latin1_General_CP1251_CS_AS If I check quieries above on database with SQL_Latin1_General_CP1_CI_AS collation then it works fine again. Could someone clarify - is it bug or expected behaviour?
View Replies !
Selecting The Same Column Twice In The Same Where Clause
Hi :From a crystal report i get a list of employee firstnames as a stringinto my store procedure. Why is it comming this way ? hmmmmmm it's aquestion for me too.ex: "e1,e2,e3"here are my tablestblProjectsProjectId123tblEmployeeemployeeId FirstName1 e12 e23 e3tblProjectsToEmployeeProjectId employeeId1 11 21 32 12 23 13 23 34 14 3i need to find out the project ids all 3 of these employees worked on.so the out put i need isprojectId13How can i get it ????????????now i can use replace command to format it to a OR clause or ANDclauseSET @string= 'employeeId =' + '''' + REPLACE('e1,e2,e3',',',''' ORemployeeId = ''') + ''''some thing like this.OR clause will give me all 4 projects.in('e1','e2','e3') will give me all 4 projects.of cause AND command will not give me any.other method i tried was adding the employee table 3 times into thesame SQL string and doing some thing likeWHERE (empTable1.Firstname ='e1' AND (empTable1.Firstnamein('e2','e3'))AND (empTable2.Firstname ='e2' AND (empTable1.Firstname in('e1','e3'))AND ...and goes alone. this gives me some what i needed. but it's a verymessy way of doing it, because i get a comma seperated stringparameter i have to construct the sql string on the fly.any help or direction on this matter would greatly appreciated.thankseric
View Replies !
Cannot Check Column In Where Clause
In a stored procedure I have I have dates in the format YYYYMMDD with symbols representing the first 3 digits e.g. °30903 =20030903, and I have to convert them to proper dates, and then eliminate all old data, so I replace symbols and then convert to int SELECT af.AccomType, af.AccomRef, af.AccomName,af.address1, af.address2, bf1.RoomCode, Convert(Int,Replace(Replace(Replace(Replace(REPLAC E(Replace(MAX(bf1.EndBook),'°','200'),'´','204'),' 99','1999'),'97','1997'),'47',1947),'98','1998')) AS max_date, ............... WHERE af.Resort=@strResort AND (af.AccomType = 'H' OR af.AccomType = 'O') AND max_date>20040721 order by max_date. Problem is I get an error saying invalid column max_date. It works in the order by clause when I get rid of the 'max_date>20040721 '. Thanks
View Replies !
Using @column For Where Clause In Select
Hi, I want to do something like "select range from mytable where @ColumnToUse = 1" then "select range from mytable where @ColumnToUse = 2" etc. and @columnToUse lists a different column heading each time. I know I can put this into an "exec ('select range...')" type statement, but it's really helpful if I don't evaluate all my variables at this stage in my scripts. Can anyone help? THanks Dan
View Replies !
Multi-column IN Clause
Hi, I have a [TestTable] table with three rows. The pair of columns [Test1] and [Test2] are id, the [Test3] is a data column. First, I get a table variable with list of id pairs. Next, I would like to update the rows of that ids. However, I have not found the elegant way how to do it. For one column it is simple, just IN clause, which does not work (or I could not find how) for multi-columns. Does someone have a hint? Thanks, Martin Note: The example bellow is dummy; on the other hand, I hope it shows the important points. Please, do not beat me on syntax errors. Code Block DECLARE @MyTableVar table( Test1 int NOT NULL, Test2 int NOT NULL ); SELECT [Test1],[Test2] INTO @MyTableVar FROM [TestTable] WHERE [Test3] = '%dd%'; UPDATE [TestTable] SET [Test3] = [Test3] + 'ds' WHERE ([Test1], [Test2]) IN (SELECT [Test1], [Test2] FROM @MyTableVar);
View Replies !
Problem With WHERE Clause When Column Length &> 255
Hello, I am using the JDCB-ODBC driver for my app, but one of the columns in my WHERE clause is 255 characters long. Because of this no rows are returned even though the statement should return 1 or 2 rows. I've tried other JDBC-ODBC drivers too and they have the same problem. Additionally, I've tried using RTrim(), Substring(), etc and it still will not work....any ideas? Is it a driver bug? Anyone know of a driver that will work? Sample code.... ResultSet rs = dbRetrieve.getStatement().executeQuery( sql ) ; if (rs.next()) { // Never gets here } Thanx!
View Replies !
Computed Column In Where Clause - QUERY Help
Hi I need suggestion for a query. Consider following 2 tables. Table-1 "T1" ----------- |ID|Name |1 |abc |2 |def |3 |erw |4 |rwg |5 |her Table-2 "T2" ---------- |ID|Qty |1 |12 |1 |2 |2 |22 |3 |10 |2 |14 I want a query which displays ID, Name and MAX(Qty) for each item where Max(Qty)>=10 i.e. result should be Result ---------- |ID|Name|Qty |1 |abc |12 |2 |def |22 |3 |erw |10 I tried: Select t1.*, (Select Max(Qty) From T2 where ID=t1.ID) as MaxQty FROM T1 t1 WHERE MaxQty>=10 But it fails as computed or inline query columns can not be added in where clause. However following works: Select t1.*, (Select Max(Qty) From T2 where ID=t1.ID) as MaxQty FROM T1 t1 WHERE (Select Max(Qty) From T2 where ID=t1.ID) >=10 BUT IS IT OPTIMIZED? Please suggest an optimized way to handle such scenarios.
View Replies !
Column Name Conflicts With T-SQL Clause Keyword
I am busy extending a VB6 app to talk to SQL Server Express 2005 and have come across a naming conflict. Some of the columns in the application's Access 97 tables is "index" which obviously exists as a T-SQL keyword and therefore any queries I perform including this column throws a syntax error. I tried prefixing the columns with their table names as in TableName.Index, but this still throws up the syntax error which I thought was a bit odd. I preferably want a fix that will be Access as well as T-SQL compliant but if that's not possible I will just write a string converter that does the job based on anyone's suggestions. TIA
View Replies !
WHERE Clause Using Different Column Passed By Parameter
Hi all, I'd think this is possible but I'm having trouble getting data returned from the query. Fields PART_NUMBER and INTERNAL_SKU exist in the SKU table. This will be inside a SP. If user passes 'PN' as first parameter then I'd need to have the WHERE clause by PART_NUMBER, if he passes 'SK' (or anything else for now) then the WHERE clause shold be by SKU. Can't I just build the WHERE by replacing @SearchField with its value ? I've looked up the CASE statement but I don't think it does what I need. DECLARE @strSearchType varchar(2) DECLARE @strSearchValue varchar(15) DECLARE @SearchField varchar(15) set @strSearchType = 'PN' set @strSearchValue = '1234567' IF @strSearchType = 'PN' begin set @SearchField = 'PART_NUMBER' end ELSE begin set @SearchField = 'INTERNAL_SKU' end SELECT SKU as 'SKU', PART_NUMBER as 'PartNumber', DESCRIPTION as 'Description' FROM SKUs WHERE @SearchField = @strSearchValue FOR XML PATH('SKU'), ROOT('Response') Thanks, ST
View Replies !
Multiple Values For Single Column In Where Clause
how does one specify multiple values for a single column in a where clause? example: SELECT fname, lname FROM tblContacts WHERE (state = 'MI','CA','AZ','TN','NJ') if my memory serves me there is an IN() value list operator but I can't remember the syntax :confused:
View Replies !
Where Clause Changing Based On NULL Column(s)
Hello DBAs: I am having difficulty constructing a where clause. I have 4 columns in a table. Col1 is never NULL. Col2,3,4 may or may not contain NULL values. Here is the situation. 1. Col2,3,4 are NULL WHERE Col1 = condition 2. Col2 is NULL, 3 may or may not be NULL. When Col3 is NOT NULL, Col4 may or may not be NULL where col1 and (col3(Not Null values) OR Col4(Not Null values)) = condition. How do I construct this logic. Please help
View Replies !
Using The AS Clause In A SQL Stored Proc -- Problem Using Datetime Column
I'm trying to concatenate fields in SQL stored proc for use in textfield in asp.net dropdownlist. I'm running into a problem when I tryto use a DateTime field, but can't find the answer (so far) on theInternet. Was hoping someone here would know?My sql stored proc:SELECT AnomalyID, DateEntered + ', ' + Station + ', ' + Problem As'SelectInfo'FROM tblAnomalyWHERE WorkOrder=@varWO AND Signoff=NullORDER BY DateEnteredbut I get the error:The conversion of a char data type to a datetime data type resulted inan out-of-range datetime value.I'm not the brightest bulb on the block, so any clues greatlyappreciated!Thanks, Kathy
View Replies !
Using The ORDER BY Clause When The Ordered Column Is Not Needed In The SELECT Statement
Greetings, I have a C# application that calls a stored procedure to query the database (MSSQL 2005). I only have one field/column returned from the query but I need that column ordered. How do I use the ORDER BY clause without returning the index column which does the sorting? The first example is NOT what I want. I want something that works like the second example which only returns the 'Name' column. ALTER PROCEDURE [dbo].[MyProcedure] AS BEGIN SELECT DISTINCT A.Name, A.index FROM ... ... ORDER BY A.[Index], A.Name ASC END ALTER PROCEDURE [dbo].[MyProcedure] AS BEGIN SELECT DISTINCT A.Name FROM ... ... ORDER BY A.[Index] END Thanks
View Replies !
GROUP By Clause Or DISTINCT Clause
Hi, can anyone shed some light on this issue?SELECT Status from lupStatuswith a normal query it returns the correct recordcountSELECT Status from lupStatus GROUP BY Statusbut with a GROUP By clause or DISTINCT clause it return the recordcount= -1
View Replies !
Filtering Results In The Where Clause Vs A Having Clause
I am working with a vendor on upgrading their application from SQL2K to SQL2K5 and am running into the following. When on SQL Server 2000 the following statement ran without issue: UPDATE dbo.Track_ID SET dbo.Track_ID.Processed = 4 --Regular 1 leg call thats been completed WHERE Processed = 0 AND LegNum = 1 AND TrackID IN ( SELECT TrackID FROM dbo.Track_ID GROUP BY TrackID HAVING MAX(LegNum) = 1 AND TrackID + 'x1' IN ( SELECT dbo.Track_ID.TrackID + 'x' + CONVERT(NVARCHAR(2), COUNT(dbo.Track_ID.TrackID)) FROM dbo.Track_ID INNER JOIN dbo.transactions ON dbo.Track_ID.SM_ID = dbo.transactions.sm_session_id GROUP BY dbo.Track_ID.TrackID ) ) Once moved to SQL Server 2005 the statement would not return and showed SOS_SCHEDULER_YIELD to be the waittype when executed. This machine is SP1 and needs to be upgraded to SP2, something that is not going to happen near time. I changed the SQL to the following, SQL Server now runs it in under a second, but now the app is not functioning correctly. Are the above and the following semantically the same? UPDATE dbo.Track_ID SET dbo.Track_ID.Processed = 4 --Regular 1 leg call thats been completed WHERE Processed = 0 AND LegNum = 1 AND TrackID IN ( SELECT TrackID FROM dbo.Track_ID WHERE TrackID + 'x1' IN ( SELECT dbo.Track_ID.TrackID + 'x' + CONVERT(NVARCHAR(2), COUNT(dbo.Track_ID.TrackID)) FROM dbo.Track_ID INNER JOIN dbo.transactions ON dbo.Track_ID.SM_ID = dbo.transactions.sm_session_id GROUP BY dbo.Track_ID.TrackID ) GROUP BY TrackID HAVING MAX(LegNum) = 1 )
View Replies !
Having Clause Without GROUP BY Clause?
Hi, What is HAVING clause equivalent in the following oracle query, without the combination of "GROUP BY" clause ? eg : SELECT SUM(col1) from test HAVING col2 < 5 SELECT SUM(col1) from test WHERE x=y AND HAVING col2 < 5 I want the equivalent query in MSSQLServer for the above Oracle query. Also, does the aggregate function in Select column(here the SUM(col1)) affect in anyway the presence of HAVING clause?. Thanks, Gopi.
View Replies !
SQL Inner Join Clause And The Where Clause
Hi everyone, I saw some queries where SQL inner join clause and the where clause is used at the same time. I knew that "on" is used instead of the "where" clause. Would anyone please exaplin me why both "where" and "on" clause is used in some sql Select queries ? Thanks
View Replies !
Diff In On Clause And Where Clause?????
hi.. i have basic question like what is differance between conditions put in ON clause and in WHERE clause in JOINS???? see conditions that shown in brown color select d1.SourceID, d1.PID, d1.SummaryID, d1.EffectiveDate, d1.Audit, d1.ExpirationDate, d1.Indicator from[DB1].[dbo].[Implicit] d1 inner join [DB2].[dbo].[Implicit] d2 on d1.SummaryID=d2.SummaryID AND d1.ListType = d2.ListType AND (d1.EffectiveDate <= d2.ExpirationDate or d2.ExpirationDate is null) AND (d1.ExpirationDate >= d2.EffectiveDate or d1.ExpirationDate is null) whered1.ImplicitID >= d2.ImplicitID AND (d1.SourceID<>d2.SourceID OR (d1.SourceID IS NULL AND d2.SourceID IS NOT NULL) OR (d1.SourceID IS NOT NULL AND d2.SourceID IS NULL) ) select d1.SourceID, d1.PID, d1.SummaryID, d1.EffectiveDate, d1.Audit, d1.ExpirationDate, d1.Indicator from[DB1].[dbo].[Implicit] d1 inner join [DB2].[dbo].[Implicit] d2 on d1.SummaryID=d2.SummaryID AND d1.ImplicitID = d1.ImplicitIDAND d1.ListType = d2.ListType AND (d1.EffectiveDate <= d2.ExpirationDate or d2.ExpirationDate is null) AND (d1.ExpirationDate >= d2.EffectiveDate or d1.ExpirationDate is null) whered1.ImplicitID >= d2.ImplicitID AND (d1.SourceID<>d2.SourceID OR (d1.SourceID IS NULL AND d2.SourceID IS NOT NULL) OR (d1.SourceID IS NOT NULL AND d2.SourceID IS NULL) ) another thing... if we put AND d1.ImplicitID = d1.ImplicitID condition in second query then shall we remove d1.ImplicitID >= d2.ImplicitID from WHERE clause????
View Replies !
Top Clause With GROUP BY Clause
How Can I use Top Clause with GROUP BY clause? Here is my simple problem. I have two tables Categories Products I want to know Top 5 Products in CategoryID 1,2,3,4,5 Resultset should contain 25 Rows ( 5 top products from each category ) I hope someone will help me soon. Its urngent thanks in advance regards Waqas
View Replies !
How To Refer A Column When The Referencing Column Is An Identity Column
Hi all, The requirement is to have a table say 'child_table', with an Identity column to refer another column from a table say 'Parent_table'.. i cannot implement this constraint, it throws the error when i execute the below Alter query, ALTER TABLE child_table ADD CONSTRAINT fk_1_ct FOREIGN KEY (child_id) REFERENCES parent_table (parent_id) ON DELETE CASCADE the error thrown is : Failed to execute alter table query: 'ALTER TABLE child_table ADD CONSTRAINT fk_1_ct FOREIGN KEY (child_id) REFERENCES parent_table (parent_id) ON DELETE CASCADE '. Message: java.sql.SQLException: Cascading foreign key 'fk_1_ct' cannot be created where the referencing column 'child_table.child_id' is an identity column. any workarounds for this ?
View Replies !
TSQL - Using ALTER TABLE - ALTER COLUMN To Modify Column Type / Set Identity Column
Hi guys, If I have a temporary table called #CTE With the columns [Account] [Name] [RowID Table Level] [RowID Data Level] and I need to change the column type for the columns: [RowID Table Level] [RowID Data Level] to integer, and set the column [RowID Table Level] as Identity (index) starting from 1, incrementing 1 each time. What will be the right syntax using SQL SERVER 2000? I am trying to solve the question in the link below: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2093921&SiteID=1 Thanks in advance, Aldo. I have tried the code below, but getting syntax error... ALTER TABLE #CTE ALTER COLUMN [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT; I have also tried: ALTER TABLE #CTE MODIFY [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
View Replies !
Alter Table Add Column - How Do You Add A Column After Say The Second Column
When you use "Alter Table add Column", it adds the column to the end of the list of fields. How do you insert the new column to position number 2 for instance given that you may have more than 2 columns? Create table T1 ( a varchar(20), b varchar(20), c varchar(20)) Alter table add column x varchar(20) so that the resulting table is T1 a varchar(20), x varchar(20), b varchar(20), c varchar(20) Can this be done programmatically?
View Replies !
ALTER TABLE DROP COLUMN LastUpdated Failed Because One Or More Objects Access This Column.
Hi I’m trying to alter a table and delete a column I get the following error. The object 'DF__Morningst__LastU__19EB91BA' is dependent on column 'LastUpdated'. ALTER TABLE DROP COLUMN LastUpdated failed because one or more objects access this column. I tried deleting the concerned constraint. But the next time I get the same error with a different constraint name. I want to find out if I can dynamically check the constraint name and delete it and then drop the column. Can anyone help.IF EXISTS(SELECT 1FROM sysobjects,syscolumnsWHERE sysobjects.id = syscolumns.idAND sysobjects.name = TablenameAND syscolumns.name = column name)BEGIN EXECUTE ('ALTER TABLE tablename DROP CONSTRAINT DF__SecurityM__DsegL__08C105B8')EXECUTE ('ALTER TABLE tablenameDrop column columnname)ENDGO
View Replies !
Cast/Convert Mmddyy In String To New DB_DATETIMESTAMP Column In Derived Column Transformation
Hi, I have dates in "mmddyy" format coming from the sources and they are older dates of mid 80s like 082580 for instance. When I cast it this way (DT_DBTIMESTAMP) Source_Date , It says ok but throws a runtime error. When I hardcode a date in same format, (DT_DBTIMESTAMP) "082580" , It becomes red (an indication of syntax error) . Please note that we use double quotes in expressions in Derived Column Transformation; So an anticipation that using double quotes over single ones would be the syntax problem would be wrong. Any help in this will sincerely be appreciated. Thanks
View Replies !
Error Invalid Column Name (In Sqlserver 2005) While Giving Alias Column Name
ALTER procedure [dbo].[MyPro](@StartRowIndex int,@MaximumRows int) As Begin Declare @Sel Nvarchar(2000)set @Sel=N'Select *,Row_number() over(order by myId) as ROWNUM from MyFirstTable Where ROWNUM Between ' + convert(nvarchar(15),@StartRowIndex) + ' and ('+ convert(nvarchar(15),@StartRowIndex) + '+' + convert(nvarchar(15),@MaximumRows) + ')-1' print @Sel Exec Sp_executesql @Sel End --Execute Mypro 1,4 --->>Here I Executed Error Select *,Row_number() over(order by myId) as ROWNUM from MyFirstTable Where ROWNUM Between 1 and (1+4)-1 Msg 207, Level 16, State 1, Line 1 Invalid column name 'ROWNUM'. Msg 207, Level 16, State 1, Line 1 Invalid column name 'ROWNUM Procedure successfully created but giving error while Excuting'. Please anybody give reply Thanks
View Replies !
Importing Data From Oracle9i CLOB Column To MS SQL Server Text Column
Hi everyone,I encountered an error "Need to run the object to perform this operationCode execution exception: EXCEPTION_ACCESS_VIOLATION" When I try to import data from Oracle to MS SQL Server with EnterpriseManager (version 8.0) using DTS Import/Export Wizard. There are 508 rowsin Oracle table and I did get first 42 rows imported to SQL Server.Anyone knows what does the above error message mean and what causes therest of the row failed importing?Thanks very much in advance!Rene Z.--Posted via http://dbforums.com
View Replies !
Derived Column Usage When Column Does Not Exist In Source (but Exists In Destination)
Posted - 09/10/2007 : 15:53:26 Hey all - got a problem that seems like it would be simple (and probably is : ) I'm importing a csv file into a SQL 2005 table and would like to add 2 columns that exist in the table but not in the csv file. I need these 2 columns to contain the current month and year (columns are named CM and CY respectively). How do I go about adding this data to each row during the transformation? A derived column task? Script task? None of these seem to be able to do this for me. Here's a portion of the transformation script I was using to accomplish this when we were using SQL 2000 DTS jobs: '********************************************************************** ' Visual Basic Transformation Script '************************************************************************ ' Copy each source column to the destination column Function Main() DTSDestination("CM") = Month(Now) DTSDestination("CY") = Year(Now) DTSDestination("Comments") = DTSSource("Col031") DTSDestination("Manufacturer") = DTSSource("Col030") DTSDestination("Model") = DTSSource("Col029") DTSDestination("Last Check-in Date") = DTSSource("Col028") Main = DTSTransformStat_OK End Function *********************************************************** Hopefully this question isnt answered somewhere else, but I did a quick search and came up with nothing. I've actually tried to utilize the script component and the "Row" object, but the only properties I'm given with that are the ones from the source data. thanks in advance! jm
View Replies !
How Can I Set Constant Padding Between The Columns Of The Column Chart(stacked Column Sub-type)?
Hi All, I am working on a column chart type (stacked column sub-type) report. Our customer requires us that the space(padding) between the columns should be a constant(including the space between the Y-axis and the first column). I know how to set the width of the columns, but I really don't know how to set the width of the space between them. The columns just varies the space between them automatically according to the number of the columns (the number of the columns is not certain). Thanks a lot in advance! Danny
View Replies !
DataBinder.Eval Is Saying My Column Doesn't Exist, Probably Because It Has A Brackets [ ] In The Column Name
I am using a SQL command in ASP.NET to send a query to a an OLAP cube that returns a dynamic set of data that I load into a datatable and then bind to a GridView. I have made my own ITemplate implementaton for displaying and formatting the data, and the following line is causing me problems: RawValue = DataBinder.Eval(row.DataItem, "[Month].[Month].[MEMBER_CAPTION]") The error returned is: Month is neither a DataColumn nor a DataRelation for table My guess as to what is happening is that it sees the brackets in the field name and stops reading the field name at [Month], when the actual field name is much longer. I know that it knows about the column name because it displays it correctly in the header. Since I am loading this from an OLAP cube the names of my columns vary based on the criteria so I cannot alias the column because I don't know exactly which columns will be displayed. Does anyone know how I might get the DataBinder.Eval function to work with fields that contain square brackets [ and ] ? If I use the GridView's "auto-generate fields" option it will show the data (and this is the column name) but I lose all control over formatting and the other custom code I'm writing in my ITemplate interface. Thanks
View Replies !
Query To Find A Value In Column B Based On An Aggregate Function On Column A?
Hi,Suppose I have a table containing monthly sales figures from my shopbranches:Branch Month Sales-----------------------London Jan 5000London Feb 4500London Mar 5200Cardiff Jan 2900Cardiff Feb 4100Cardiff Mar 3500The question I am trying to ask is this: in which month did each branchachieve its highest sales? So I want a result set something like this:Branch Month----------------London MarCardiff FebI can do a "SELECT Branch, MAX(Sales) FROM MonthlySales GROUP BY Branch" totell me what the highest monthly sales figure was, but I just can't figureout how to write a query to tell me which month corresponded to MAX(Sales).Ideas anyone?Cheers,....Andy
View Replies !
PROBLEM: How To Set A Char Datatype Column Behave Like An Identity Column ??
Hi... Everybody, I am new to using SQL Server and I have the following problem. I have a table/s that have the primary key/s of datatype char. Since I cannot set the Identity property to char datatype column, so before I insert a record everytime: I need to increment the primary key column value first with some code and then prepare the recordset and then perform the insert operation. Is there a way I can do this same procedure through an Insert trigger on that table of interest ? This will make things easy because the Insert trigger shall handle the required logic for getting the new value for the primary key column and prepare the new recordset from the temporary INSERTED table in the trigger. EX: Suppose I have a table with the following columns: CREATE TABLE [Sample] AS a char(6) PRIMARY KEY, b smalldatetime, c int Supposing that the format for the PK column is '000001', '000002' so on.... Is it possible to perform an insert operation such as: INSERT INTO [Sample] ([b], [c]) VALUES('01-01-1999', 100) and the Insert Trigger for the table [Sample] will take care of the adding the next PK column value automatically ? Thanks in advance, BR, Sudhakar
View Replies !
Need Script To Modify A Formula Column Into Normal Column With Default Value.
I have a table called test with 4 fields namley studentname, Mark1, Mark2, total (formula column). Created table test in the following structure, create table test (studentname varchar(50), Mark1 numeric, Mark2 numeric, total as ([Mark1]+[Mark2])) Now I need to drop formula nature of this column total and assign default value '0'. I like to know how to do it using T-Sql script. Thanks for your help in advance.
View Replies !
Insert Data Into A Destination Column Which Doesnt Have An Input Column
Hi, I was wondering how I can complete a column (which doesnt have an input one) with data. For example: I have a sql query which bring data of 3 columns ID | FISRT NAME | LAST NAME 1 MIKE MORGAN 2 SARA JOHANES So, I will insert that data in a FLAT FILE CONNECTION MANAGER, which I configured with 3 columns and I did the corresponding mapping in the FLAT FILE DESTINTATION. Now, If I add one more column in the FLAT FILE CONNECTION MANAGER, I will not have it mapped to a input one, obviously. So, what I need is to add one more column to the flat file destination and complete it with zeros values in it. Probably I can solve this part by introducing a DERIVED COLUMN and there I can configure the zeros that I want to add to the column. But I'm not sure if I can do that without having a input column. So, the question will be, how can I add one column to a flat file which doesnt have a input and introduce any value that I want to it? Hope I was clear Thanks for your help. Beli
View Replies !
Nested Table Key Column Is Not Bound To An Input Rowset Column
Hi! I have a "little" problem with nested case model: -- "normal" database: DROP TABLE [unitInfo] ; GO CREATE TABLE unitInfo ( unitID INT PRIMARY KEY , beginDate SMALLDATETIME , area VARCHAR(10) , partSize INT , y2predict MONEY ) ; go INSERT INTO unitInfo VALUES (1, '2007-02-01', 'home', 42, 10.0) ; INSERT INTO unitInfo VALUES (2, '2007-03-05', 'home', 43, 11.0) ; INSERT INTO unitInfo VALUES (3, '2007-02-02', 'office', 11, 11.4) ; INSERT INTO unitInfo VALUES (4, '2007-02-01', 'office', 10, 33.6) ; INSERT INTO unitInfo VALUES (5, '2007-02-01', 'office', 42, 44.1) ; CREATE TABLE unitLog ( id INT IDENTITY(1, 1) PRIMARY KEY , logtime SMALLDATETIME , -- combination of logtime/unitID is unique unitID INT , -- "FK" on unitInfo m1 FLOAT , m2 FLOAT ) INSERT INTO [unitLog] VALUES ('2007-01-01', 1, 43.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-01', 2, 43.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-01', 3, 63.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-02', 4, 432.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-02', 1, 43.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-03', 1, 423.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-04', 1, 432.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-05', 2, 43.0, 441.0) INSERT INTO [unitLog] VALUES ('2007-01-06', 2, 43.0, 4.0) INSERT INTO [unitLog] VALUES ('2007-01-06', 3, 43.0, 4.0) INSERT INTO [unitLog] VALUES ('2007-01-07', 1, 4.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-08', 1, 3.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-08', 1, 43.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-08', 1, 43.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-09', 2, 143.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-10', 3, 143.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-11', 4, 43.0, 144.0) INSERT INTO [unitLog] VALUES ('2007-01-11', 5, 43.0, 144.0) INSERT INTO [unitLog] VALUES ('2007-01-12', 2, 43.0, 144.0) INSERT INTO [unitLog] VALUES ('2007-01-13', 4, 413.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-14', 4, 43.0, 414.0) INSERT INTO [unitLog] VALUES ('2007-01-14', 1, 43.0, 44.0) INSERT INTO [unitLog] VALUES ('2007-01-20', 1, 43.0, 414.0) INSERT INTO [unitLog] VALUES ('2007-01-22', 1, 43.0, 414.0) -- SSAS: CREATE MINING STRUCTURE NestedStructure ( unitID LONG KEY, beginDate DATE CONTINUOUS, area TEXT DISCRETE , partSize LONG CONTINUOUS, y2predict DOUBLE CONTINUOUS , logdata table ( [id] LONG KEY, unitID LONG CONTINUOUS , m1 DOUBLE CONTINUOUS, m2 DOUBLE CONTINUOUS ) ) ALTER MINING STRUCTURE NestedStructure ADD MINING MODEL nestedModel ( unitID , beginDate REGRESSOR, area , partSize REGRESSOR ,y2predict REGRESSOR PREDICT_ONLY , logdata ([id] , unitID , m1, m2 ) ) USING Microsoft_Decision_Trees /* version 1*/ insert into NestedStructure ( unitID, beginDate, area, partSize, y2predict , logdata(skip,unitID, m1, m2)) openrowset('sqloledb', Server=myserver;Trusted_Connection=yes;, 'Shape {select * FROM mydb.dbo.unitInfo } Append ( { select id, unitID, m1, m2 from mydb.dbo.unitLog } Relate unitID to unitID ) as logdata ') Parsing the query ... OLE DB error: OLE DB or ODBC error: Syntax error or access violation; 42000. Parsing complete Where is the error? /*version 2*/ CREATE MINING STRUCTURE NestedStructure1 ( unitID LONG KEY, beginDate DATE CONTINUOUS, area TEXT DISCRETE , partSize LONG CONTINUOUS, y2predict DOUBLE CONTINUOUS , logdata table ( [id] LONG KEY, unitID LONG CONTINUOUS , m1 DOUBLE CONTINUOUS, m2 DOUBLE CONTINUOUS ) ) ALTER MINING STRUCTURE NestedStructure1 ADD MINING MODEL nestedModel1 ( unitID , beginDate REGRESSOR, area , partSize REGRESSOR ,y2predict REGRESSOR PREDICT_ONLY , logdata ([id] , unitID , m1, m2 ) ) USING Microsoft_Decision_Trees insert into mining structure NestedStructure1 ( unitID, beginDate, area, partSize, y2predict , logdata(skip,unitID, m1, m2)) Shape {openquery(dsnDB,'select * FROM mydb.dbo.unitInfo') } Append ( { openquery(dsnDB,'select id, unitID, m1, m2 from mydb.dbo.unitLog') } Relate unitID to unitID ) as logdata Parsing the query ... Error (Data mining): INSERT INTO error: The '[logdata].[id]' nested table key column is not bound to an input rowset column. Parsing complete Remark that combination logtime/unitID is the natural key in unitLog. "ID" is the surrugate key. What is wrong here...?
View Replies !
Create Multi Column View From Single Column Data
I have two tables, one a data table, the other a product table. I want to perform a join on the two tables with values distributed into columns based on the value in the month field. data_table product_code month value 350 1 10 350 2 20 350 3 30 product_table product_code profit_center 350 4520 result_view product_code profit_center mon1 mon2 mon3 350 4520 10 20 30 My current query gives the following result result_view product_code profit_center mon1 mon2 mon3 350 4520 10 0 0 350 4520 0 20 0 350 4520 0 0 30 Any direction toward a solution would be appreciated. Am using SS2005.
View Replies !
Help With A WHERE Clause
I have an insert statement that reads: SELECT AppointmentID, PatientNo, PatientSurname, PatientForename, ConsultantName, HospitalName, Date, CONVERT (varchar, Time, 8), AppointmentStatus FROM [Appointment] WHERE ([AppointmentId] = @AppointmentId) I also need to add another WHERE clause. This clause will mean that if the date is within 14 days of the actual date it will not ba able to be selected need help writing this not sure how to write it Thanks in advance Mike.
View Replies !
Sql Where Clause - Help
Hey guys, I'm a bit weak when it comes to doing ands and or's. I know what i want, but when I put it into statement, i dont get the results that i want. I have 3 fields in my where clause. ID, LW, and LWU. The code is as follows:WHERE (LASTVISIT BETWEEN '1 / 1 / 95 12 : 00 : 00 AM' AND '1 / 1 / 06 12 : 00 : 00 AM') AND (ID NOT LIKE '%6%') AND (ID NOT LIKE '%7%') AND (ID NOT LIKE '%8%') AND (LW <> 1) AND (LWU <> 'test') OR (LASTVISIT BETWEEN '1 / 1 / 95 12 : 00 : 00 AM' AND '1 / 1 / 06 12 : 00 : 00 AM') AND (ID IS NULL) AND (LW <> 1) AND (LWU <> 'test') I have a range of dates that I want to grab, in there I do not want any records where ID has 6,7,8 and I only want records where LW does not equal 1. UP to this point, it works fine. I get all the records that only return these values. However, the moment I add where LWU does not equal 'test'. it does not return the values I want. Furthermore, why can I not put this whole string into one and clause? I never understood why I had to create a second line following OR. the longer this query gets the more I get confused. Any help?
View Replies !
Like Clause
I'm trying to do a simple ... SELECT ... FROM .... WHERE ... LIKE clause and i think my syntax is off. WHile using sql server ...... is the syntax Where Name LIKE '%variable%' ?????? Or should I be using something differnent. Thank you in advance for any help.
View Replies !
IN Clause
hi alli need to create a sql statement that receives some values - my doubt is only about how to build that sql statementi've heard something about IN clause but could not apply it - could someone give any sample?First page: I have a textbox with some emails e.g. a@a.com, b@b.com, c@c.com etcSecond page: SELECT * FROM Table1 WHERE Field = ... IN ???thanks in advance
View Replies !
WHERE Clause In VWD
Really hope somebody can help me out here. It is kinda urgent. In order to bind data to a gridview using VWD, i need to pass as parameter a property value to the select statement. I have no idea to do this. Problem is... when using the visual tool to configure the datasource, i cant seem to 'feed' the property value as parameter. (WHERE) For some reason it only accepts parameters from forms, controls, querystrings etc. Does anybody know how to do this? I cant bind the value to some control. It has to come from this public property. many thanks in advance!!
View Replies !
Using CONTAINS Clause
Hi, I am working on a project involving text searching. I created a fulltext catalog on the database and scheduled it for every one minute. I created a fulltext index on a table and added some columns. I scheduled it as the database catalog. I ran a simple query like this in the query analyzer but got an error message that the catalog does not exist! SELECT * FROM tbl_extra_skills WHERE CONTAINS(ITSkills, 'Word') What am I doing wrongly?
View Replies !
Help With WHERE CLAUSE
I'm having a heck of time with this where clause. I have a table that contains client addresses, a client can have more than one address. So some of the addresses may be seasonal. I need to return only the current address based on a flag MailTo (bit) and a date range, just the month and day, the start and end are datetime datatypes. Here is what i have tried: I would really would like it to work on a range of month and day based on the startdate and enddate fields and the MailTo flag. The table looks like this; tblClientAddresses: Address_ID,Client_ID,Address,Address2,City,State,Zip,Country,AddressType,StartDate, EndDate,MailTo WHERE (A.MailTo=1) AND (A.EndDate Is Null OR DatePart(mm,A.Enddate) >= DatePart(mm,GETDATE()) AND DatePart(dd,A.Enddate) >= DatePart(dd,GETDATE())) Thank you for any help!
View Replies !
For XML Clause
I'm trying to turn a product table into an XML file to create anheirarchical menu, and I was wondering if there was any easy way to dothis. The table is (simplified) below:Create table product(category varchar,subcategory varchar,name varchar)and I want the XML to represent the category structure as below:<Categories><sucategories><products>.....</products></subcategories></Categories>Thanks,John
View Replies !
OR In The WHERE Clause?
I am trying to create a system that will select candidates for a jobbased on certain criteria (i.e. Supperted States)The candidates are allowed to choose up to 5 supported states. Theproblem comes when creating the query to pull the candidates out.I can get it to work with only one supported state, no problem. But Ihave no idea how to tell the DB to look through SupportedState1 ORSupportedState2 OR SupportedState3 OR SupportedState4 ORSupportedState5 to find the particular state that the job is in.Does an OR operator exist; or at least some mechanism for achievingthis? Maybe there is a smarter way to implement this instead of 5seperate fields for the supported states?Thanks so much,Alex
View Replies !
SQL WHERE CLAUSE HELP
I need a little help with an assignment....Basically I have a table with several PRODUCTSPRODUCT(P_ID, P_Name, P_Class, P_Price, Product_Supplier)Anyways....I need to display:List each Product Class, number of items in the class and the averagePrice of the items in the class. List only those classes that have morethan three (3) items.I have thisSelect P_Class, COUNT(P_Class), AVG(P_Price) Quote:
View Replies !
|