YOU ALL REQUESTED TO HELP ME TO COMEOUT FROM PROBLEM : I HAVE A TABLE NAME PLUCK
IN WHICH DATA STORE: MONYEAR EMPCODE PDATE(ddmmyyy) JOBCODE HCD kg
022006 A01608P 01/02/2006 LA N 0
022006 A01608P 02/02/2006 LA N 0
022006 A01608P 03/02/2006 LA N 0
022006 A01608P 04/02/2006 LA N 0
022006 A01608P 05/02/2006 LH N 0
022006 A01693P 01/02/2006 PL N 21
022006 A01693P 02/02/2006 PL N 25
022006 A01693P 03/02/2006 PL N 15
022006 A01693P 04/02/2006 PL N 25
022006 A01693P 05/02/2006 LH N 0
BUT I WANT REPORT LIKE : 022006 A01608P LA N LA N LA N LA N LH N
022006 A01693P 21 N 25 N 15 N 25 N LH N
(IF JOBCODE = PL THAN INSTEAD OF JOBCODE KGPLUCK IS SHOWN..)
Pls guide how to write the SQL to achive the report...
Thanks
ASM
---sample data insert
USE NORTHWIND
CREATE TABLE PLUCK (MONYEAR CHAR(6), EMPCODE CHAR(7), PDATE SMALLDATETIME,JOBCODE CHAR(2), HCD CHAR(1), KGPLUCK INT)
INSERT INTO PLUCK VALUES('022006', 'A01608P','01/02/2006','LA','N',0);
INSERT INTO PLUCK VALUES('022006', 'A01608P','02/02/2006','LA','N',0);
INSERT INTO PLUCK VALUES('022006', 'A01608P','03/02/2006','LA','N',0);
INSERT INTO PLUCK VALUES('022006', 'A01608P','04/02/2006','LA','N',0);
INSERT INTO PLUCK VALUES('022006', 'A01608P','05/02/2006','LH','N',0);
INSERT INTO PLUCK VALUES('022006', 'A01693P','01/02/2006','PL','N',21);
INSERT INTO PLUCK VALUES('022006', 'A01693P','02/02/2006','PL','N',25);
INSERT INTO PLUCK VALUES('022006', 'A01693P','03/02/2006','PL','N',15);
INSERT INTO PLUCK VALUES('022006', 'A01693P','04/02/2006','PL','N',25);
INSERT INTO PLUCK VALUES
('022006', 'A01693P','05/02/2006','LH','N',0);
I need to send the result of a procedure to an update statement.Basically updating the column of one table with the result of aquery in a stored procedure. It only returns one value, if it didnt Icould see why it would not work, but it only returns a count.Lets say I have a sproc like so:create proc sp_countclients@datecreated datetimeasset nocount onselect count(clientid) as countfrom clientstablewhere datecreated > @datecreatedThen, I want to update another table with that value:Declare @dc datetimeset @dc = '2003-09-30'update anothertableset ClientCount = (exec sp_countclients @dc) -- this line errorswhere id_ = @@identityOR, I could try this, but still gives me error:declare @c intset @c = exec sp_countclients @dcWhat should I do?Thanks in advance!Greg
I have an Execute SQL Task that executes "select count(*) as Row_Count from xyztable" from an Oracle Server. I'm trying to assign the result to a variable. However when I try to execute I get an error: [Execute SQL Task] Error: An error occurred while assigning a value to variable "RowCount": "Unsupported data type on result set binding Row_Count.".
Which data type should I use for the variable, RowCount? I've tried Int16, Int32, Int64.
---------------------------------------------------------------------- I executed it in my SQL Server Management Studio Express and I got: Commands completed successfully. I do not know where the result is and how to get the result viewed. Please help and advise.
HI, I ran a select * from customers where state ='va', this is the result...
(29 row(s) affected) The following file has been saved successfully: C:outputcustomers.rpt 10826 bytes
I choose Query select to a file then when I tried to open the customer.rpt from the c drive I got this error message. I am not sure why this happend invalid TLV record
As the topic suggests I need the end results to show a list of shows and their dates ordered by date DESC. Tables I have are structured as follows:
SHOWS showID showTitle
SHOWACCESS showID remoteID
VIDEOS videoDate showID
SQL is as follows:
SELECT shows.showID AS showID, shows.showTitle AS showTitle, (SELECT MAX(videos.videoFilmDate) AS vidDate FROM videos WHERE videos.showID = shows.showID) FROM shows, showAccess WHERE shows.showID = showAccess.showID AND showAccess.remoteID=21 ORDER BY vidDate DESC;
I had it ordering by showTitle and it worked fine, but I need it to order by vidDate. Can anyone shed some light on where I am going wrong?
I am trying to code a WHERE xxxx IN ('aaa','bbb','ccc') requirement but it the return values for the IN keyword changes according to another column, thus the need for a CASE function.
WHERE GROUP.GROUP_ID = 2 AND DEPT.DEPT_ID = 'D' AND WORK_TYPE_ID IN ( CASE DEPT_ID WHEN 'D' THEN 'A','B','C' <---- ERROR WHEN 'F' THEN 'C','D ELSE 'A','B','C','D' END )
I kept on getting errors, like
Msg 156, Level 15, State 1, Line 44Incorrect syntax near the keyword 'WHERE'. which leads me to assume that the CASE ... WHEN ... THEN statement does not allow mutiple values for result expression. Is there a way to get the SQL above to work or code the same logic in a different manner in just one simple SQL, and not a procedure or T-SQL script.
I'm using a subquery to return a delivery charge line as a column in the result set. I want to see this delivery charge only on the first line of the results for each contract. Code and results are below.
declare @start smalldatetime declare @end smalldatetime set @start = '2015-03-22 00:00' -- this should be a Sunday set @end = '2015-03-28 23:59' -- this should be the following Saturday
In this example, I only want to see the delivery charge of 125.00 for the first line of contract HU004377. For simplicity I have only shown the lines for 1 contract here, but there would normally be many different contracts with varying numbers of lines, and I only want to see the delivery charge once for each contract.
Hi All, I need to For Each loop tied back to a SQL result set. This is what I have so far, I know its not much but I'm stuck. Thanks soooo much!TimDim conn As SqlConnectionDim comm As SqlCommandDim reader As SqlDataReaderDim connectionstring As String = ConfigurationManager.ConnectionStrings("Magic").ConnectionStringconn = New SqlConnection(connectionstring)comm = New SqlCommand("Select Distinct([_Group_]) from _Smdba_._Groupdet_ Where [_InActive_:] = 0", conn) Tryconn.Open()reader = comm.ExecuteReader() For Each (FOR EACH SQL RECORD) 'I'm going to put some code in here.... reader.Close()Catch dberrorlabel.Text = "Error Loading Admin Panel"Finally conn.Close()End Try
In 6.5 I ran a SELECT query with a specific WHERE clause. It gave me a result set of 430 rows. But when I use the same conditions in WHERE clause in UPDATE, it updated only 420.
Dear All,Can we do multiple result row as a single row while selection ..?Request you to provide the SQL if we can achieve this...For Eg,Table Name = Employeeid - EmployeeName - addresstype - address1 - address2 - City1 - AAA - permanent - 231 - First Street - XYA2 - AAA - Temporary - 343 - Second Street - XYAExpecting Result as a Single row as below,id - EmployeeName - Address1 - Address21 - AAA - 231/First Street/XYA - 343/Second Street/XYAThanks in advanceRgds,Ganapathi sundaram.G
Hello,Is there a way to merge the result of a query into one row?For example, let say I want the a list of name of people of 20 year soldMy result will look like that: NAME1 john2 Mike3 Craig I would like to have the result in one row: NAME1 John, Mike, CraigIs there a way to do that?Thanks
Dear Experts Here is my code: SqlConnectioncn = new SqlConnection(ConfigurationManager.ConnectionStrings["SimvipConnectionString"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("SP_SEARCH", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@TypeOfSim", Request.QueryString["NID"])); cmd.Parameters.Add(new SqlParameter("@CategoryID", Request.QueryString["CID"])); cmd.Parameters.Add(new SqlParameter("@Price", Request.QueryString["L"])); cmd.Parameters.Add(new SqlParameter("@Price2", Request.QueryString["S"])); cmd.Parameters.Add(new SqlParameter("@Title", Request.QueryString["keyword"])); cmd.Connection.Open(); cmd.ExecuteNonQuery(); SqlDataAdapter sqlAdapter1 = new SqlDataAdapter(); sqlAdapter1.SelectCommand = cmd; DataSet ds = new DataSet(); sqlAdapter1.Fill(ds, "ds");
CollectionPager1.DataSource = ds.Tables["ds"].DefaultView; CollectionPager1.BindToControl = DataList1; DataList1.DataSource = CollectionPager1.DataSourcePaged; } My problem is when there is no result(no item in database), the DataList1 will display the text "some text will display here" instead of empty page. In FormView I know the option <EmptyDataTemplate>. But in the DataList I don't know how to do this. I am a beginner. Can anybody show me how....Thanks a lots
I have an account field which has datatype string. I want to only get those values which are in between 0-199. I used select sum(t.a_trans_amt) Credit from a_account a, a_transaction t where a.a_account_num between '0' and '199'and t.a_account_id=a.a_account_id and t.a_debit_credit_ind='C'but this query also including those values which have starting 3 digit in between 0-199. I don't know how to fix this problem . Can anybody help me on this issue. Thanks in Advance.
Hi y'all, I have a problem in my query I think maybe you guys could help.I have this query:SELECT dbo.BOS_GL_Workplace.WpszState, Emp2.szName, Emp1.szName AS szEmpName, Emp1.szEmployeeId, dbo.BOS_PI_Division.szName AS Divisi, dbo.BOS_PI_Team.szDescription,dbo.BOS_SD_Route.szRouteId, dbo.BOS_SD_Route.szDescription, dbo.BOS_SD_Route.szScheduleId, dbo.BOS_SD_RouteItem.szCustId, dbo.BOS_SD_Route.szOpUserId,dbo.BOS_AR_Customer.szCustId ,dbo.BOS_AR_Customer.szName, dbo.BOS_AR_Customer.CustszAddress_1 AS SendAddres, dbo.BOS_AR_Customer.szTaxId, dbo.BOS_AR_Customer.CustszAddress_1 AS CollectAddress, dbo.BOS_AR_Customer.CustszCity, dbo.BOS_AR_Customer.CustszZipCode, dbo.BOS_AR_Customer.szStatus, dbo.BOS_AR_CustSales.szPaymentTermId, dbo.BOS_AR_CustSales.decCreditLimit,BOS_AR_Customer.dtmStart,BOS_AR_Customer.dtmLastUpdated FROM dbo.BOS_PI_Employee Emp1 LEFT OUTER JOIN BOS_PI_Employee Emp2 on Emp1.szSupervisorID = Emp2.szEmployeeID Left outer join dbo.BOS_GL_Workplace ON Emp1.szWorkplaceId = dbo.BOS_GL_Workplace.szWorkplaceId LEFT OUTER JOIN dbo.BOS_PI_Division ON Emp1.szDivisionId = dbo.BOS_PI_Division.szDivisionId LEFT OUTER JOIN dbo.BOS_PI_Team ON Emp1.szTeamId = dbo.BOS_PI_Team.szTeamId LEFT OUTER JOIN BOS_SD_Route on Emp1.szEmployeeId = BOS_SD_route.szOPuserId LEFT OUTER JOIN BOS_SD_RouteItem on BOS_SD_Route.szRouteId = BOS_SD_RouteItem.szRouteID LEFT OUTER JOIN BOS_AR_Customer on BOS_SD_RouteItem.szCustID = BOS_AR_Customer.szCUstID LEFT OUTER JOIN BOS_AR_CustSales on BOS_AR_Customer.szCustId = BOS_AR_CustSales.szCustID --order by BOS_PI_Employee_1.szNameWhen I query it's working fine the results is the way as I expected. But when I add where--and--clause like this :WHERE Emp2.szName >= 'JACK ANDREWS' AND Emp2.szName <='RICK COLLINS'it's only showing the header and no result at all, why ??? can you guys help me please, I appreciate any kinds of help. Thanks. FYI: I use SQL Server 2000 Best Regards.
Hi Ive just started with asp.net and this question is maby stupid but I cant find the error.
Problem: I am trying to make a loginpage with the username and password stored in a database. The page do not generates any error then runnin BUT it is not possible to log in. The sql-procedure always return -1 even if the username do exist.
-------------------------------------------- Function MyAuthentication(strUsername As String, strPassword As String) As Integer
Dim myConn As SQLConnection Dim myCmd As SQLCommand Dim myReturn As SQLParameter Dim intResult As Integer Dim conn As String
conn = ConfigurationSettings.AppSettings("Generala") myConn = New SQLConnection(conn)
myCmd = New SQLCommand("MyAuthentication",myConn) myCmd.CommandType = CommandType.StoredProcedure
If intResult < 0 Then If intResult = -1 Then lblMessage.Visible = true lblMessage.Text = "Username Not Registered!<br><br>" Else lblMessage.Visible = true lblMessage.Text = "Invalid Password!<br><br>" End If End If
Is it possible to retrieve a particular row from a result set? For eg if my query returns 5 rows and i want to just retrieve the 3rd row from the result....is it possible? If yes...can someone tell me the syntax for it....would appreciate the gr8 help...
How can I read a query result set (which are of type VARCHAR) into an array? i.e the result set comprises of just one column and 5 rows and i want to save these into an array to easily extract each row whenever i want to. Hope I have conveyed my idea clearly.
I am tring to find out wheather a SQL Agent job is running. I was wanting to put the result from sp_help_job into a cursor and check whether @@fetch_status was successful. if it fails then job is not running
the below code fails because when declaring a cursor expects a select statement.
is there anyway to get result from a sp into a cursor thanks
declare @sql varchar(100) set @sql = 'sp_help_job null, ''event_167'', @job_aspect = ''job'', @execution_status = 1' declare Job_Cursor cursor for sp_help_job @job_name = 'some_job_name', @job_aspect = 'job', @execution_status = 1 open Job_Cursor fetch next from Job_Cursor if @@fetch_status <> 0 begin print 'Job is not runnning' end if @@fetch_status = 0 begin print 'Job is runnning' end close Job_Cursor deallocate Job_Cursor
Hi,all, I ran the two queries and I thought it would be the same, but it's different. Can you explain to me.
Query 1: result---52 rows select s.InsuredSurname, s.email from studyUSA s join interMedical I on s.email=I.email where convert(char(10), s.enrolldate, 126)>= '2004-01-01' and convert(char(10), s.enrolldate, 126) <='2005-05-20' and (s.agentcode not like '162%') and (s.agentcode not like '17%') and s.agentcode <> '130844'
Query 2: result--14 rows
select s.InsuredSurname, s.email from tis_studyUSA s where convert(char(10), s.enrolldate, 126)>= '2004-01-01' and convert(char(10), s.enrolldate, 126) <='2005-05-20' and s.email IN (Select I.Email from tis_InterMedical I) and (agentcode not like '162%') and (agentcode not like '17%') and agentcode <> '130844'
Hi: I create a DTS package in 'Copy SQL Objects Task' to transfer 3 stored procedures from my local SQL msdb to remote testing msdb database. Execution is 'successful' but the destination server msdb does not have the 3 stored procedures.
Any hint on this 'vanished' copy objects? thanks -D
My results from using cursor is different from using temp table? Instead of using cursor, I did a group by into a tmp tables. The where clauses are the same. Most of the results are the same, but for some. But when I restrict the where clause, the results are ALL the same.
[Phone] [Time] [Result] 5551212 0812 No Answer 5551212 1203 Answering Machine ... 5551213 0813 Busy 5551213 1634 No Answer
So as you can see, Phone contains phone number, Time contains time the number was called and [Result] contains the outcome. Now I need a query that gives me all the Phones on which the LAST outcome was No Answer. I don't need the Phone if it had a No Answer sometime during the day but not the last Result. I just need the last result. I need unique phone numbers obviously.
The Time field is DateTime. So am using it to sort right now. But I am pretty sure there's a better way.
I must also mention that I just have readonly rights and cannot create a new table if required.