Need Suitable Pure SQL Query
Hi
I have Pure SQL DataBase name of Table as per given Coloumn Name.
User Name StartDate EndDate
Mr.Jack 01/04/2010 05/04/2010
Mr.Perlin 07/04/2010 10/04/2010
Mr.Tinklin 01/05/2010 05/05/2010
Mr.Kerlin 12/04/2010 15/04/2010
Now I am using asp.net Form Using C#...
Name --> TextBox
StartDate -> TextBox
EndDate --> TextBox
Now User enter the Dates after Click Save Button....
Here SQL Query Check Whether the User Dates Clause into Data Base Date's.
For Examble..
User Enter Start Date = 04/04/2010, EndDate =08/04/2010
Now Query it check SQL DataBase, Already 01/04/2010 to 10/04/2010 Available so Dont allow Save.... only allow various dates...
---------------- This is task Condition -------
i am using SQL Query
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate ='02/04/2010' --// This is User Start Date coming from Text Box
SET @EndDate = '10/04/2010' --// This is User End Date coming from Text Box
IF NOT EXISTS (SELECT PollID FROM Polls WHERE (StartDate<= CAST (CONVERT(VARCHAR,@StartDate,101) AS DATETIME) OR EndDate <= CAST (CONVERT (VARCHAR,@EndDate,101) AS DateTime)) AND STATUS<>'D')
SELECT 'OK ALLLOW'
ELSE
SELECT 'NOT ALLOW'
But it is not working Correctly....
Pls give some correctful query for solve task Condition
By
Riyaz
Edited by: 798225 on Sep 28, 2010 10:37 PM
Edited by: 798225 on Sep 28, 2010 10:52 PM
Now I am developing Polls Application in asp.net
I am using Polls Concept,
DateBase Name : Polls
Fields : PollID PollName StartDate EndDate UserID
In Asp.Form Having
User Name : TextBox
PollName: TextBox
StartDate: TextBox
EndDate: TextBox
Submit - Button
Task Details
Whenever User Click after fillup all data's... then SQL Query Check
if StartDate or EndDate is exists in Between DataBase Date's.....
Condition true means dont allow save.. else Save.....
Examble:
PollID PollName StartDate EndDate UserName
01 Sample 23/09/2010 26/09/2010 Klit
02 Sample 2 29/09/2010 30/09/2010 Jack
Now User given follwing details and click Submit,
User Name : James
PollName: Test
StartDate: 22/09/2010
EndDate: 27/09/2010
Submit - Button
Here User StartDate: 22/09/2010 , EndDate: 27/09/2010
SQL Query Check ,
Condtion 1 : Those dates are avilable in Datebase???
Result: Yes
Because, Sample Poll date is 23/09/2010 to 26/09/2010, here Start Date is Not Exists, But End Date Exists.
So dnt allow Save Operation....
Now User Again given follwing details and click Submit,
User Name : James
PollName: Test
StartDate: 27/09/2010
EndDate: 28/09/2010
Submit - Button
Here User StartDate: 27/09/2010 , EndDate: 28/09/2010
SQL Query Again Check ,
Condtion 1 : Those dates are avilable in Datebase???
Result: No
Because, Sample Poll date is 23/09/2010 to 26/09/2010,
Sample1 Poll Date is 29/09/2010 to 30/09/2010
here Start Date is Not Exists, But End Date Not Exists.
So Allow Save Operation....
This a My Task....
Could You give SQL Query for help to Check given condition??
regd
Riayz
Edited by: Riyaz on Sep 30, 2010 1:08 AM
Similar Messages
-
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Hello,
I need Oracle Payroll SQL Query with result:
First_name, Last_name, Payment_amount, Pay_date, Payroll_Frequency, Employement_status
Any Help would be greatful appreciatedYou will need the following tales.
per_all_people_f, per_all_assignments_f,pay_run_results,pay_run_result_values
Query would e something like :
select papf.first_name,
papf.last_name,
prrv.*
From apps.per_all_people_f papf
apps.per_all_assignments_f paaf
apps.pay_run_results prr,
apps.pay_run_result_values prrv
Where papf.person_id = paaf.person_id
and papf.business_group_id = paaf.business_group_id
and papf.current_employee_flag = 'Y'
and paaf.primary_flag ='Y'
and paaf.assignment_type = 'E'
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
and prr.assignment_id = paaf.assignment_id -
Need to adjust SQL query for left outer join in Crystal Reports 2008.
I need to change this SQL 2005 query.....
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id
WHERE
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
To this query in Crystal Reports Report Writer:
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id AND
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
I can't seem to get the left outer join function of Crystal Reports to emulate the same SQL query in SQL 2005. Any ideas on how I can create this same query in Crystal 2008?
Thanks,
Dominic
Edited by: Dominic Carissimi on Oct 28, 2008 7:55 PM
Edited by: Dominic Carissimi on Oct 28, 2008 7:56 PMIf you want the list of values for command level parameter then you need to add another command like
select PropertyField from table
and delete the links between this command and the existing command.
Now go to field explorer and edit the command level parameter and make it as dynamic and add the property field from newly added command.
Hope this helps!
Raghavendra -
Hi all,
I have data in the following manner:
CASE_NUMBER HOURS FLAG
1000 10 0
1000 20 0
1000 30 1
1000 40 0
1000 50 1
Here I need to Calculate the total hours for a Case_number till i see the flag as 1.
Here the result must be 10+20+30 Hrs
Another Example
CASE_NUMBER HOURS FLAG
2000 10 1
2000 20 1
Here the result must be only 10.
I am struggling to write a SQL query for this.
Anyones help will be very much greatful
Thanks in Advance
Regards,
Sengathir SubbarayanLook up analytical functions.
something like sum(hours) OVER (PARTITION BY case_number ORDER BY something)
will give you the sum for all rows.
Then you probably want to "throw away" those rows after the flag maybe by summing the flag column too, and throw away all those where the flag is greater than 1 and where it is equal to 1 except for the first one.
I suspect you actually have some other column (other than the number of hours) that define your order - that's what you put in the ORDER BY.
Jon -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
Help needed in framing SQL query.
Hi,
I have table having following schema:
PRODUCT_ID INT
DATE DATETIME
ITEMS_SOLD INT
This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
Any help to get the SQL query will be appreciated.
Thanks,
Akshay.PRODUCT_ID DATE ITEMS_SOLD
1 10/10/2011 3
1 11/10/2011 3
1 12/10/2011 3
1 13/10/2011 3
1 16/10/2011 5
2 10/10/2011 4
2 11/10/2011 4
2 12/10/2011 4
2 13/10/2011 4
2 14/10/2011 4
2 15/10/2011 4
2 16/10/2011 4
Output:
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
2 4 7
Explanation of results:
The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
2 4 7
Other case where same PRODUCT_ID have different units sold on each day should be ignored.
I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
-Akshay. -
Need help with sql query dates
Hi,
I have a sql query where i need to extract some info between given dates. The where clause of this query is as follows:
WHERE CPD_BUS_UNIT=:ESI_PRM_1
AND CPD_VOUCHER_DATE >= :P_DATE_FROM
AND CPD_VOUCHER_DATE < (:P_DATE_TO+1)
When i execute the query in toad, i can view the data but not the execution plan.It gives an error ORA-00932-Inconsistent Datatypes.
But when i remove (+1) from :P_DATE_TO, i can c the execution plan and data. Will the data be different from the previous one.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1
AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM)
AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1) Regards -
I am trying to execute a pure SQL statement. But my DB adapter is not fetching any output.
select installation_type from oid_staa_desc_mapping where Acode in ('A','B')
I am not sure why this doesn't work.
Regards,
BalajiHi,
Read the following blog post:
http://soa-howto.blogspot.com/2009/05/how-to-use-sql-query-having-in-clause.html
Regards.
D -
I have a table with Columns as as below
id number primary key
object_name varchar2(100)
object_value varchar2(100)
Data is stored as follows
id object_name object_value
10 prop_num 436
20 city dallas
40 Misc 1 90
50 Misc 1 desc min amount
60 Misc 2 700
70 Misc 2 desc interest amount
80 Misc 3
80 Misc 3 desc
SQL should return result as shown below
id object_name object_value
10 prop_num 436
20 city dallas
40 min amount 90
50 interest amount 700
I have done this through plsql code by creating temp table. But I need to do it in a sql query. I am stuck here
Any pointers/help is appreciated
Thanks
Edited by: user9327712 on Mar 11, 2010 8:14 AMI have a table where the ids are stored.
*"object name"* column values are actually another table columns stored as rows here. So in our example prop_num, city,Misc 1, Misc 1 desc, Misc 2, Misc 2
desc,Misc 3 , Misc 3 desc are all columns. These would not change any time
The column object_value has values stored for respective columns.
436, dallas , 90 , min amount , 700 , interest amount are all column values. So these can change.
id object_name object_value
10 prop_num 436
20 city dallas
40 Misc 1 90
50 Misc 1 desc min amount
60 Misc 2 700
70 Misc 2 desc interest amount
80 Misc 3
90 Misc 3 desc
Edited by: user9327712 on Mar 11, 2010 9:57 AM
Edited by: user9327712 on Mar 11, 2010 10:00 AM
Edited by: user9327712 on Mar 11, 2010 10:00 AM -
Need a SCCM SQL Query Report for Installed Software with Packages and Applications.
I need a report that will show the number of installs of all of the workstations applications and packages over a given period of time.
This will let us know how effective our deployments are and how well the on-demand software is being adopted.
Any help?Your Install Source might be an option as most SCCM deployments will install from C:\Windows\ccmcache\xx [where xx is a random folder name]. Most software vendors will put an install source in the registry, but not all do, so it won't be completely accurate.
When software is installed manually, the install source path won't be C:\Windows\ccmcache\xx.
Here is a SQL query I have for Install Source:
SELECT v_GS_COMPUTER_SYSTEM.Name0 as 'Computer Name', v_GS_INSTALLED_SOFTWARE.ProductName0 as 'Software Title', v_GS_INSTALLED_SOFTWARE.InstallSource0 as 'Install Source', v_GS_INSTALLED_SOFTWARE.ProductVersion0 as 'Version', v_GS_INSTALLED_SOFTWARE.InstalledLocation0
as 'Installed Location', v_GS_INSTALLED_SOFTWARE.InstallDate0 as 'Install Date'
FROM v_GS_COMPUTER_SYSTEM INNER JOIN v_GS_INSTALLED_SOFTWARE ON v_GS_COMPUTER_SYSTEM.ResourceID = v_GS_INSTALLED_SOFTWARE.ResourceID
WHERE v_GS_INSTALLED_SOFTWARE.ProductName0 like '%Office 365 Pro%'
ORDER BY v_GS_COMPUTER_SYSTEM.Name0 -
Need generic dynamic sql query to generate nodes depending on dealer levels
Input table:
create table #test(dealerid integer ,dealerlvl integer)
insert into #test values(1,1)
insert into #test values(1,2)
insert into #test values(1,3)
insert into #test values(1,4)
insert into #test values(2,1)
insert into #test values(2,2)
insert into #test values(2,3)
insert into #test values(2,4)
insert into #test values(2,5)
insert into #test values(2,6)
go
create table #test2(dealerid integer,node integer,prntnode integer,dealerlvl integer)
insert into #test2 values (1,234,124,2)
insert into #test2 values (1,123,234,1)
insert into #test2 values (1,238,123,2)
insert into #test2 values (1,235,238,3)
insert into #test2 values (1,253,235,4)
insert into #test2 values (2,21674,124,3)
insert into #test2 values (2,1233,21674,1)
insert into #test2 values (2,2144,1233,2)
insert into #test2 values (2,2354,2144,3)
insert into #test2 values (2,24353,2354,4)
insert into #test2 values (2,245213,24353,5)
insert into #test2 values (2,2213,245213,6)
Expected result :
I have two test case here with dealerID1 and dealerID 2
Result for DealerID1
Result needed for DealerID2:
the levels for dealers might change (Dealer1 has 4 levels, and Dealer 2 has 6 levels) so i need to create an dynamic sql query which lists each node as separate columns depending on the levels.
I have hacked the query to give the result I need
select a.dealerid,a.node as Lvl1,b.node as lvl2,c.node as lvl3,d.node as lvl4
from #test2 a
join #test2 b on a.node=b.prntnode
join #test2 c on b.node=c.prntnode
join #test2 d on c.node=d.prntnode
where a.dealerid=1 and a.dealerlvl=2
select a.dealerid,a.node asLvl1,
b.node as lvl2,c.node as lvl3,d.node as lvl4,e.node as lvl5,f.node as lvl6--,a.dealerlvl,a.dealerid
from #test2 a
join #test2 b on a.node=b.prntnode
join #test2 c on b.node=c.prntnode
join #test2 d on c.node=d.prntnode
join #test2 e on d.node=e.prntnode
join #test2 f on e.node=f.prntnode
where a.dealerid=2 and a.dealerlvl=3
I am sure there is a better way to do this with dynamic sql. please help.
Thanks-- Dynamic PIVOT
DECLARE @T AS TABLE(y INT NOT NULL PRIMARY KEY);
DECLARE
@cols AS NVARCHAR(MAX),
@y AS INT,
@sql AS NVARCHAR(MAX);
-- Construct the column list for the IN clause
SET @cols = STUFF(
(SELECT N',' + QUOTENAME(y) AS [text()]
FROM (SELECT DISTINCT dealerlvl AS y FROM dbo.test2) AS Y
ORDER BY y
FOR XML PATH('')),
1, 1, N'');
-- Construct the full T-SQL statement
-- and execute dynamically
SET @sql = N'SELECT *
FROM (SELECT dealerid, dealerlvl, node
FROM dbo.Test2) AS D
PIVOT(MAX(node) FOR dealerlvl IN(' + @cols + N')) AS P;';
EXEC sp_executesql @sql;
GO -
I have a table, say VEHICLE, which contains MODEL, CITY, SOLD NUMBERS.
The table may be like this
MODEL SOLD NUMBERS CITY
Honda 1200 New York
Toyota 900 New Jersy
Honda 1700 California
Ford 1500 Mexico
Ford 1600 Delhi
Toyota 800 Chennai
Mercedes 1000 New York
I need to build a query which will return me the model name and the number of items sold.
The output of the query should be having the number of Honda sold and number of Ford sold, irrespective of the city.
The rest of the models should be combined and their combined number of items sold should be displayed as single row.
The output structure may be
MODEL SOLD NUMBERS
Honda 2900
Ford 3100
OTHERS 2700 (combined toyota and mercedes)
Please help me out regarding this.Although you asked this question in a wrong forum , still I will answer this question
as I belong to the Pl/SQL forum too.
Try the following query :
SELECT MODEL , SUM(SOLD NUMBERS) FROM
(SELECT DECODE(MODEL,'Honda','Honda','Ford','Ford','OTHERS') MODEL,SOLD NUMBERS FROM VEHICLE) A
GROUP BY MODEL--------------------------------------------
Hope this helps.
Thanks -
Hi Friends,
I am too muchconfused about an sql query. I've created a html page where I select one radio button . The value of this radio button is passed to the query.Now the out put of the query is used in developing the output.
For illustration I show you the source code.
Radio Button Selection page.
<form action="service.html" method="post"> <h3><strong>Services Available</strong></h3> <p> <label> <input type="radio" name="service" value="si" /> Institutions</label> <br /> <label> <input type="radio" name="service" value="sc" /> Corporate_Offices</label> <br /> <label> <input type="radio" name="service" value="sr" /> Restaurent_Cafe</label> <br /> </p> <label> <input type="submit" value="Submit" /> </label> </form>
Now the query page-
<sql:query var="empList" scope="session"> select <c:out value="${param.service}" /> from map_service where cityname = ? <sql:param value="${param.cityname}" /> </sql:query>
Now I need to generate output with the given below value in the next page-
<c:out value="${param.service}" />
This value show value as si, sc sr only where I need the database table value as per selection.
I am really confused that what I should write as <c:out value="${...
My database table has attributes as cityname, si, sc, sr. etc.
when some one select si from radio button the value of radio button is passed to sql query and the value which is selected on the table after query should be used in developing output result please help.Dear Friend Is it not possible for any of you to give me a clue that if I've to get the output of *?* from the query what I can write in syntax.
<sql:query var="empList" scope="session">
select ? from map_service
where cityname = ?
<sql:param value="${param.service}" />
<sql:param value="${param.cityname}" />
</sql:query>
<c:out value="${empList.param.service}" />Output of the value of ? from the database select ? from map_service Any idea -
Complete novice needs help getting SQL Query into Crystal Reports XI
Post Author: MissMarnie
CA Forum: Data Connectivity and SQL
So I was given an intro level web course and a monster reference guide in prep to format a report. One of our developers wrote me everything I need for the report into a SQL Query and now I'm supposed to format it in CR XII literally do not know what to do from here. I'm able to set up the correct server as a datasource, if that's useful, but I don't know how to make the querey into a bunch of formattable fields in CR. If anyone can walk me through this, I'd be so grateful. I've attempted to look up SQL query in both the help and the book but I keep hitting a wall. The help dialog says things like "press this button" with no reference to what "this button" is. I'm sure it's obvious to the knowledgeable but I'm in a complete fog. Thanks in advancePost Author: synapsevampire
CA Forum: Data Connectivity and SQL
IF you're trying to get assistance with setting up a query as the source for a report, try posting your Crystal version and the database type.
Different software works differently.
In CR 9 and above, under the connection to the database you'll see Add Command. Select that and you can paste the query in.
As for not knowing how to generate a report, that requires experience, there's no generic solution of course..
-k
Maybe you are looking for
-
ERROR MESSAGE AMT : CANNOT DELETE TOKEN AFTER IT WAS ASSIGNED TO A ROLE
We are working on the setup in our sandbox environment and we have noticed that we are unable to delete tokens and remove the protection on BO's. the following message appears : "CANNOT DELETE TOKEN AFTER IT WAS ASSIGNED TO A ROLE" There is no Token
-
Sending to multiple addresses and using BCC
I'm using Mail and Address book to send a basic email (no images or anything like that) to my mailing list. I beleive my server (Sympatico) has a restriction on the number of recipients - 99. But I'm sending to less than that. When I put the addresse
-
I recently renewed my icloud, since then I have been trying to use itunes match but it keeps coming up with error 4040?
-
Flip4mac/quicktime causes sleep problems
I installed Flip4mac and when i try to watch YouTube the computer spontaneously goes to sleep. I uninstalled and it stopped, but it's caused me so much grief in the past that it started happening when i used quicktime among other things and i had to
-
Smartform problem : bold black edge appearing on window edges at output
Hi , I have a problem . When i to print my form with device lpxx it does not give any problem on output . But same when i try it using devive lpzz a dark bold edge appears on some windows edges of the form when output taken in pdf format . Kindl