SQL/ASP - Timout Problem W/ Particular Statement

Dec 21, 2005

Hello

Config : SQL 2000 on WIN 2000 (IIS 5.0)

In my ASP page for some queries i have this error :

Microsoft OLE DB Provider for SQL Server error '80040e31'
Timeout expired


My asp page calls a stored procedure passing many parameters.
I used the SQL profiler to get the exact stored procedure with all
parameters.

If i execute stored procedure in the Query Analyzer, it's execute
successfully in 3-4 seconds.
After executing 2-3 times the stored procedure in the Query Analyzer,
the error disapear from the ASP Page which runs fine and quickly.

My procedure is too long to be detailled here, but to do short, it's
look for the availabilities (the stock) of different products for a
desired length of time, with different parameters (color,size,etc..).
My main table look like :

Day | Id_prod | Provider | Stock | Price
1 1 1 2 3
1 2 1 1 2
1 1 2 4 5
1 2 2 0 4
2 1 1 1 9
2 2 1 3 7
2 1 2 1 7
2 2 2 4 6
...
.....
366 1 1 4 4
366 2 1 1 5
366 1 2 2 8
366 2 2 0 9

The primary key is : day,Provider,Id_prod
And the main sql statment in my stored procedure :

IF @end>@begin
INSERT INTO #tmptable
SELECT Id_prod,Provider,MIN(stock) FROM mytable WHERE day >= @begin
AND day <=@end
ELSE
INSERT INTO #tmptable
SELECT Id_prod,Provider,MIN(stock) FROM mytable WHERE day>=@begin OR
day<=@end)

Note : I use a temporary table to use paging, i just display 10
results/pages.

The problem only appears if @end<@begin (exemple; which product is
available from dec 29th to jan 2nd in blue color)

Any help would be much appreciated.
Thank and happy Christmas.



PS:If i set the timeout CommandTimeout = 9999 the problem is resolve but
it's not a solution for me.

View 6 Replies


ADVERTISEMENT

Query Timout

Mar 11, 2004

OK...i have a query that looks something like what is below and is generated on the fly:


SELECT DISTINCT c.*
FROM SOMETHING c
WHERE ( X IN
(SELECT Y
FROM Z
WHERE ZXY = '1') AND
( X IN
(SELECT Y
FROM Z
WHERE ZXY = '4')OR
( X IN
(SELECT Y
FROM Z
WHERE ZXY = '9')AND
( X IN
(SELECT Y
FROM Z
WHERE ZXY = '7'))

as you can tell something like this will take a long time to process......what is the best way to handle a query like such?....is cursor the way to go......it's driving me nuts!

Trey

View 6 Replies View Related

Getting ODBC Timout Errors.

Feb 8, 2001

Hi Folks,

I'm getting a ODBC timout error when i try to login to SQL server. After the initial error i try connecting again, and it works. Why is it giving me an error in the first place and then when i try reconnecting it'll work? Does anyone know. Could it be i need to update my ODBC drivers. This error all of a sudden just started happening.

View 1 Replies View Related

Timout Expired From ASP.Net App, But Not In Management Studio

Nov 27, 2007

 I'm having an interesting problem.  I have a stored proc that executes from SSMS in less than 1 second regardless of the parameters I give it.  But when I execute it from my ASP.Net app with certain parameters, it will always timeout.  The web app is on my dev machine as is SMSS.  The database (SQL Server 2005) is one a different machine a few states away.  I have never seen this before ... it's quite aggravating.I found a similar thread where someone stated they fixed this by changing some database settings, but didn't specify what settings.Any help would be greatly appreciated. 

View 1 Replies View Related

Timout - SQL Not Responding Under Heavy Load

Apr 1, 2005

Hi,
Our app uses an NT4 SQL 2k box and a Win2k IIS box.  To fulfill the text searching requirements we've had to use dynamic SQL (created within a large SP).  This query searches about 8000 rows in a flat table (which we create and keep up to date using a scheduled SP which trawls the underlying tables).  It's a complicated SP, and can return all 8000 rows (I think we're winning the battle to have this capped though).
When we get about 50 users hitting the app and doing searches simultaneously, performance drops severely (20 secs+ for a query rather than ~2 secs), and we get a lot of errors - which report that:
Source: .Net SqlClient Data ProviderMessage: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
We also get a lot of Invalid Viewstate errors, which i'm totally baffled by, and the odd IIS Access Denied error - as if authentication (NTLM) is timing out.
Neither the Web not the SQL machines are being hit very hard - the web server in particular is not under any strain whatsoever.
It doesn't appear to be related to connection pooling, from the logged error messages we're getting.
Does anyone have ANY suggestions as to where I should be looking?! 

View 3 Replies View Related

Multiple Tables Used In Select Statement Makes My Update Statement Not Work?

Aug 29, 2006

I am currently having this problem with gridview and detailview. When I drag either onto the page and set my select statement to pick from one table and then update that data through the gridview (lets say), the update works perfectly.  My problem is that the table I am pulling data from is mainly foreign keys.  So in order to hide the number values of the foreign keys, I select the string value columns from the tables that contain the primary keys.  I then use INNER JOIN in my SELECT so that I only get the data that pertains to the user I am looking to list and edit.  I run the "test query" and everything I need shows up as I want it.  I then go back to the gridview and change the fields which are foreign keys to templates.  When I edit the templates I bind the field that contains the string value of the given foreign key to the template.  This works great, because now the user will see string representation instead of the ID numbers that coinside with the string value.  So I run my webpage and everything show up as I want it to, all the data is correct and I get no errors.  I then click edit (as I have checked the "enable editing" box) and the gridview changes to edit mode.  I make my changes and then select "update."  When the page refreshes, and the gridview returns, the data is not updated and the original data is shown. I am sorry for so much typing, but I want to be as clear as possible with what I am doing.  The only thing I can see being the issue is that when I setup my SELECT and FROM to contain fields from multiple tables, the UPDATE then does not work.  When I remove all of my JOIN's and go back to foreign keys and one table the update works again.  Below is what I have for my SQL statements:------------------------------------------------------------------------------------------------------------------------------------- SELECT:SELECT People.FirstName, People.LastName, People.FullName, People.PropertyID, People.InviteTypeID, People.RSVP, People.Wheelchair, Property.[House/Day Hab], InviteType.InviteTypeName FROM (InviteType INNER JOIN (Property INNER JOIN People ON Property.PropertyID = People.PropertyID) ON InviteType.InviteTypeID = People.InviteTypeID) WHERE (People.PersonID = ?)UPDATE:UPDATE [People] SET [FirstName] = ?, [LastName] = ?, [FullName] = ?, [PropertyID] = ?, [InviteTypeID] = ?, [RSVP] = ?, [Wheelchair] = ? WHERE [PersonID] = ? ---------------------------------------------------------------------------------------------------------------------------------------The only fields I want to update are in [People].  My WHERE is based on a control that I use to select a person from a drop down list.  If I run the test query for the update while setting up my data source the query will update the record in the database.  It is when I try to make the update from the gridview that the data is not changed.  If anything is not clear please let me know and I will clarify as much as I can.  This is my first project using ASP and working with databases so I am completely learning as I go.  I took some database courses in college but I have never interacted with them with a web based front end.  Any help will be greatly appreciated.Thank you in advance for any time, help, and/or advice you can give.Brian 

View 5 Replies View Related

SQL Server 2012 :: Create Dynamic Update Statement Based On Return Values In Select Statement

Jan 9, 2015

Ok I have a query "SELECT ColumnNames FROM tbl1" let's say the values returned are "age,sex,race".

Now I want to be able to create an "update" statement like "UPATE tbl2 SET Col2 = age + sex + race" dynamically and execute this UPDATE statement. So, if the next select statement returns "age, sex, race, gender" then the script should create "UPDATE tbl2 SET Col2 = age + sex + race + gender" and execute it.

View 4 Replies View Related

Using Conditional Statement In Stored Prcodure To Build Select Statement

Jul 20, 2005

hiI need to write a stored procedure that takes input parameters,andaccording to these parameters the retrieved fields in a selectstatement are chosen.what i need to know is how to make the fields of the select statementconditional,taking in consideration that it is more than one fieldaddedfor exampleSQLStmt="select"if param1 thenSQLStmt=SQLStmt+ field1end ifif param2 thenSQLStmt=SQLStmt+ field2end if

View 2 Replies View Related

TSQL - Use ORDER BY Statement Without Insertin The Field Name Into The SELECT Statement

Oct 29, 2007

Hi guys,
I have the query below (running okay):



Code Block
SELECT DISTINCT Field01 AS 'Field01', Field02 AS 'Field02'
FROM myTables
WHERE Conditions are true
ORDER BY Field01

The results are just as I need:


Field01 Field02

------------- ----------------------

192473 8461760

192474 22810



Because other reasons. I need to modify that query to:



Code Block
SELECT DISTINCT Field01 AS 'Field01', Field02 AS 'Field02'
INTO AuxiliaryTable
FROM myTables
WHERE Conditions are true
ORDER BY Field01
SELECT DISTINCT [Field02] FROM AuxTable
The the results are:

Field02

----------------------

22810
8461760

And what I need is (without showing any other field):

Field02

----------------------

8461760
22810


Is there any good suggestion?
Thanks in advance for any help,
Aldo.

View 3 Replies View Related

DB Engine :: Can't Use The MERGE Statement / How To Design WHERE Condition For Insert Statement

Nov 5, 2015

I've have a need with SQL Server 2005 (so I've no MERGE statement), I have to merge 2 tables, the target table has 10 fields, the first 4 are the clustered index and primary key, the source table has the same fields and index.Since I can't use the MERGE statement (I'm in SQL 2005) I have to make a double step operation, and INSERT and an UPDATE, I can't figure how to design the WHERE condition for the insert statement.

View 2 Replies View Related

SQL Server 2012 :: Update Statement With CASE Statement?

Aug 13, 2014

i was tasked to created an UPDATE statement for 6 tables , i would like to update 4 columns within the 6 tables , they all contains the same column names. the table gets its information from the source table, however the data that is transferd to the 6 tables are sometimes incorrect , i need to write a UPDATE statement that will automatically correct the data. the Update statement should also contact a where clause

the columns are [No] , [Salesperson Code], [Country Code] and [Country Name]

i was thinking of doing

Update [tablename]
SET [No] =
CASE
WHEN [No] ='AF01' THEN 'Country Code' = 'ZA7' AND 'Country Name' = 'South Africa'
ELSE 'Null'
END

What is the best way to script this

View 1 Replies View Related

How To Write Select Statement Inside CASE Statement ?

Jul 4, 2006

Hello friends,
I want to use select statement in a CASE inside procedure.
can I do it? of yes then how can i do it ?

following part of the procedure clears my requirement.

SELECT E.EmployeeID,
CASE E.EmployeeType
WHEN 1 THEN
select * from Tbl1
WHEN 2 THEN
select * from Tbl2
WHEN 3 THEN
select * from Tbl3
END
FROM EMPLOYEE E

can any one help me in this?
please give me a sample query.

Thanks and Regards,
Kiran Suthar

View 7 Replies View Related

Transact SQL :: Update Statement In Select Case Statement

May 5, 2015

I am attempting to run update statements within a SELECT CASE statement.

Select case x.field
WHEN 'XXX' THEN
  UPDATE TABLE1
   SET TABLE1.FIELD2 = 1
  ELSE
   UPDATE TABLE2
   SET TABLE2.FIELD1 = 2
END
FROM OuterTable x

I get incorrect syntax near the keyword 'update'.

View 7 Replies View Related

Compiler Is Not Recognizing My Using Statement For SglConnection Statement

Feb 4, 2006

I am using ASP.NET 2.0, and am attempting to write some code to connect to the database and query a data table. The compiler is not recognizing my SqlConnection statement. It does recognize other commands. And just to make sure, I created other sql objects such as ObjectDataSource and SqlDataSource. The compiler does not find a problem with that code.
Basically the compiler is telling me that I am missing a "using" directive. The compiler is wrong though, because I am including the statement "usingSystemData" Can someone please take a look at my code below and to see if you notice what the problem might be?  Note that I numbered the lines of code below. Note that I also tried putting lines 3 trhough 6 before line 2(The page directive) but that did not fix the problem The compiler still gives me the same compiler message.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request.Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)Source Error:
Line 21: SqlConnection sqlConn = new SqlConnection("server=localhost;uid=sa;pwd=password;database=master;");
1 <asp:sqldatasource runat="server"></asp:sqldatasource>
2 <%@ Page Language="C#"%>
3 using System;
4 using System.Data;
5 using System.Collections;
6 using System.Data.SqlClient;
7
8 <script runat=server>
9
10 protected void Page_Load(object o, EventArgs e)
11 {
12 ObjectDataSource dsa; // This works no problems from the compiler here
13 SqlDataSource ds; // This works no problems from the compiler
14
15 if (IsPostBack)
16 {
17 if (AuthenticateUser(txtUsername.Text,txtPassword.Text))
18 {
19 instructions.Text = "Congratulations, your authenticated!";
20 instructions.ForeColor = System.Drawing.Color.Red;
21 SqlConnection sqlConn = new SqlConnection("server=localhost;uid=sa;pwd=password;database=master;");
22 String sqlStmt = "Select UserName from LogIn where UserName='" + txtUsername.Text + "' and password='" + sHashedPassword + "'";
23 }
24 else
25 {
26 instructions.Text = "Please try again!";
27 instructions.ForeColor = System.Drawing.Color.Red;
28 }
29 }
30
31 }
32
33 bool AuthenticateUser(string username, string password)
34 {
35 // Authentication code goes here
36
37 }

View 1 Replies View Related

Case Statement Error In An Insert Statement

May 26, 2006

Hi All,
I've looked through the forum hoping I'm not the only one with this issue but alas, I have found nothing so I'm hoping someone out there will give me some assistance.
My problem is the case statement in my Insert Statement. My overall goal is to insert records from one table to another. But I need to be able to assign a specific value to the incoming data and thought the case statement would be the best way of doing it. I must be doing something wrong but I can't seem to see it.

Here is my code:
Insert into myTblA
(TblA_ID,
mycasefield =
case
when mycasefield = 1 then 99861
when mycasefield = 2 then 99862
when mycasefield = 3 then 99863
when mycasefield = 4 then 99864
when mycasefield = 5 then 99865
when mycasefield = 6 then 99866
when mycasefield = 7 then 99867
when mycasefield = 8 then 99868
when mycasefield = 9 then 99855
when mycasefield = 10 then 99839
end,
alt_min,
alt_max,
longitude,
latitude
(
Select MTB.LocationID
MTB.model_ID
MTB.elevation, --alt min
null, --alt max
MTB.longitude, --longitude
MTB.latitude --latitude
from MyTblB MTB
);

The error I'm getting is:
Incorrect syntax near '='.

I have tried various versions of the case statement based on examples I have found but nothing works.
I would greatly appreciate any assistance with this one. I've been smacking my head against the wall for awhile trying to find a solution.

View 10 Replies View Related

How To Use Select Statement Inside Insert Statement

Oct 20, 2014

In the below code i want to use select statement for getting customer

address1,customeraddress2,customerphone,customercity,customerstate,customercountry,customerfirstname,customerlastname

from customer table.Rest of the things will be as it is in the following code.How do i do this?

INSERT INTO EMImportListing ("
sql += " CustId,Title,Description,JobCity,JobState,JobPostalCode,JobCountry,URL,Requirements, "
sql += " IsDraft,IsFeatured,IsApproved,"
sql += " Email,OrgName,customerAddress1,customerAddress2,customerCity,customerState,customerPostalCode,

[code]....

View 1 Replies View Related

How To Show Records Using Sql Case Statement Or If Else Statement

Feb 20, 2008

i want to display records as per if else condition in ms sql query,for this i have used tables ,queries as follows


as per data in MS Sql

my tables are as follows
1)material
fields are -- material_id,project_type,project_id,qty, --

2)AB_Corporate_project
fields are-- ab_crp_id,custname,contract_no,field_no

3)Other_project
fields are -- other_proj_id,other_custname,po

for ex :
vales in table's are
AB_Corporate_project
=====================
ab_crp_id custname contract_no field_no
1 abc 234 66
2 xyz 33 20

Other_project
============
other_proj_id other_custname po
1 xxcx 111
2 dsd 222

material
=========
material_id project_type project_id qty
1 AB Corporate 1 3
2 Other Project 2 7

i have taken AB Corporate for AB_Corporate_project ,Other Project for Other_project


sample query i write :--

select m.material_id ,m.project_type,m.project_id,m.qty,ab.ab_crp_id,
ab.custname ,op.other_proj_id,op.other_custname,op. po
case if m.project_type = 'AB Corporate' then
select * from AB_Corporate_project where ab.ab_crp_id = m.project_id
else if m.project_type = 'Other Project' then
select * from Other_project where op.other_proj_id=m.project_id
end
from material m,AB_Corporate_project ab,Other_project op


but this query not work,also it gives errors

i want sql query to show data as follows


material_id project_type project_id custname other_custname qty
1 AB Corporate 1 abc -- 3
2 Other Project 2 -- dsd 7

so plz help me how can i write sql query for to show the output
plz send a sql query

View 8 Replies View Related

Help With Delete Statement/converting This Select Statement.

Aug 10, 2006

I have 3 tables, with this relation:
tblChats.WebsiteID = tblWebsite.ID
tblWebsite.AccountID = tblAccount.ID

I need to delete rows within tblChats where tblChats.StartTime - GETDATE() < 180 and where they are apart of @AccountID. I have this select statement that works fine, but I am having trouble converting it to a delete statement:

SELECT * FROM tblChats c
LEFT JOIN tblWebsites sites ON sites.ID = c.WebsiteID
LEFT JOIN tblAccounts accounts on accounts.ID = sites.AccountID
WHERE accounts.ID = 16 AND GETDATE() - c.StartTime > 180

View 1 Replies View Related

Using Select Statement Result In If Statement Please Help

Jul 11, 2007

Hello
How can i say this I would like my if statement to say:  if what the client types in Form1.Cust is = to the Select Statement which should be running off form1.Cust then show the Cust otherwise INVALID CUSTOMER NUMBER .here is my if statement.
<% If Request.Form("Form1.Cust") = Request.QueryString("RsCustNo") Then%> <%=Request.Params("Cust") %> <% Else %> <p>INVALID CUSTOMER NUMBER</p> <% End If%>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RsCustNo %>"
ProviderName="<%$ ConnectionStrings:RsCustNo.ProviderName %>" SelectCommand="SELECT [CU_CUST_NUM] FROM [CUSTOMER] WHERE ([CU_CUST_NUM] = ?)">
<SelectParameters>
<asp:FormParameter FormField="Cust" Name="CU_CUST_NUM" Type="String" />
</SelectParameters>
</asp:SqlDataSource>any help would be appreciated

View 2 Replies View Related

Where Statement Compared With Join Statement

Jan 11, 2006

for complex views should I use "where" statements or "joins" in terms of performance?

Which one is faster?

View 6 Replies View Related

If STATEMENT Within Select Statement Syntax

May 15, 2008

Hi,

I am a newbie to this site and hope someone can help....

I have a select statement which I would like to create an extra column and put an if statement in it.... Current syntax is:

if(TL_flag= '1', "yes") as [Trial Leave]

it is coming up with an error.... I can use Select case but I should not need to as this should work?

Any ideas?

View 2 Replies View Related

How To Read SQL Statement In T-SQL Statement Task?

Jun 7, 2007

hi all,



after convert from DTS to SSIS, how can i open the SQL statement? because i only saw a line in the properties of the task.



i open the DTSX in vs2005, but i can open to view the SQL statement.



in sql 2000 just double click on the SQL Task, then will popup a dialog form to show the SQL task.



please help.



thanks a lot

View 1 Replies View Related

Select Statement Within Select Statement Makes My Query Slow....

Sep 3, 2007

Hello... im having a problem with my query optimization....

I have a query that looks like this:


SELECT * FROM table1
WHERE location_id IN (SELECT location_id from location_table WHERE account_id = 998)


it produces my desired data but it takes 3 minutes to run the query... is there any way to make this faster?... thank you so much...

View 3 Replies View Related

Embedded If Statement If SQL Statement...how?

Jul 3, 2006

Greetings:

I know I've done this is Oracle before (can't remember the syntax) but how to do it in SQL Server?

It's powerful functionality if I can get it to work.

SELECT
If(Viewed = 'T', 'True', 'False') Viewed
FROM Messages

Thanks in advance for any and all guidance.

Ed in Tampa

View 2 Replies View Related

Embed SQL Statement In Another SQL Statement

Jul 20, 2005

Suppose I have an MS access database with query1 and query2. Query2 usesquery1 something like this:Select table.* from (table left join query1 on field1=field2)Now I want to make a change in query1 to change the behaviour of query2. Butthis cannot be done in a live environment because I have to shut down theapplication, make the change in the database and start the applicationagain. What I can do is make a query 3 in my application (instead of in thedatabase) that is initially does the same as query2 like this:Select table.* from (table left join -->some SQL code to embed query1<-- onfield1=field2)Once I know how to do this, I can change the "embedded" sql code to myneeds.Question is: how do I "embed" SQL code in another statement?

View 1 Replies View Related

Using IF...Else Statement SELECT Statement

Sep 7, 2006

 

Hi All,

Can some one point me in the right direction in how to construct my SQL query within my cursor?

I Have got a cursor which i am using to iterate through a table, What i am trying to do is in my statement(used to open the cursor) is compare 2 tables (the one which my cursor is iterating) to see if there is a matching row in the other table (using  both tables ID's Like So:

SELECT column_List
FROM Table1
WHERE Table1_id = Table2_id  


 so for each row  my cursor checks if there is a corresponding match in  table2... but i would like to write to an error log

and do other statements if there is no match

 how do i add this condition to my statement either using an if...else statement proceeding to the next row?

here is the statment i attempted to write:

SELECT column_List
FROM table1
WHERE
 Table1_id = Table2.id

now i want to incoporate the statements below into the statement above as a condition when table1.id <> table2.id    


IF  table1.id <> table2.id    

BEGIN
   SET @DebugMessage = 'data not live.'
   RAISERROR (@DebugMessage, 16, 1) WITH LOG
  END

essentially what i am trying to sayin my statement is:

 go to the first row

check if it has a match in table 2,

 if there is no match execute a number of statements such as error loging e.t.c

go to the next row

 repeat the previous statements 

 

...i also looked through some Case...When statements am just not sure how to put in the condition

thanks in advance

 

View 1 Replies View Related

A Sql Statement

Jul 24, 2006

This does not display more than 10 rows from the able, varchar(2000) is big enough to bring more rows, where might the problem mbe?
 
Declare @ColList varchar(2000)
Declare @CrLf varchar(10)
 
Select @CrLf=Char(13) + Char(10)
Select @ColList = COALESCE(RTRIM(LTRIM(@ColList)) + ', ' + @CrLf, '') + MyName From MyTable
Select @ColList

View 3 Replies View Related

SQL STATEMENT

Oct 30, 2006

Hi all, I gotta retrieve fields that is not null from database according to ID.There are a tota of 45 fields to retrieve, but I only needed fields that are not null. How do I retrieve fields that are not null where the id = id?

View 5 Replies View Related

SQL Statement Help

Dec 5, 2006

Hi, I am having trouble retreiving data for and application.  What I need in simple terms is the following: I have a table  called Orders that contains 2 dates - OrderDate and Received date.  However not all the fields have a ReceivedDate where as they all have an OrderDate.  What I want to do is to retreive a data set for each record which has the ReceivedDate if it has one, but if not it uses the OrderDate. Can anyone help with the SQL statement required to do this? ThanksPaul 

View 2 Replies View Related

Need Help With Sql Statement

Feb 2, 2007

Here is the deal....  I have a table in my database that has these fields. (sql server 2005 standard)

intBlog Id = int
intBlogCategoryId= int
vcBlogTitle = varchar(8000)
vcBlogShortDescription = ntext
vcBlogContent ntext
vcUsername = varchar(200)
intBlogViewed = int
dtBlogPosted = datatime
Okay here is the thing, I want to figure out how to write an sql statement that (as you see on other sites, a blog archive that goes through the DB and gets the unique month and year and then count how many blogs are in each distinct month/year.
Hope that makes sense so it looks like this
January 2007 (24)December 2006 (2)November 2006 (98)
Thanks for the help in advance.....
Joshua Folkerts

View 7 Replies View Related

Need Help With A SQL Statement

Apr 30, 2007

If you can see what I am trying to do here, how can I get this to work?
I want to list the dates in the datebase in a particular format and a count for each
 
Seems simple enough, but maybe not?
 
select count(*),x from
(select right('0' + cast(datepart(yyyy,datetime1) as char(4)),4)
+ '-' +
right('0' + cast(datepart(m,datetime1) as varchar(2)),2)
+ '-' +
right('0' + cast(datepart(d,datetime1) as varchar(2)),2) x
from users)
group by x

View 8 Replies View Related

Need Help With My SQL Statement

May 20, 2007

I am trying to figure out what is wrong with my sql statement.  It shows up right and all but my last and where clause is not working right.  I want to search the database for a parameter of searchtext but only display jobs where the expiration date is greater than todays date.  My statement is as follows:  SELECT
tblJobs.intJobID,
tblJobs.vcBusinessName,
tblJobs.vcJobTitle,
tblJobs.vcJobShortDescription,
tblJobs.vcJobExpirationDate,
tblJobs.vcJobDescription,
tblJobs.IntJobCategory,
tblJobs.intJobSchedule,
tblJobs.vcPositionExperience,
tblJobs.vcJobInquiry,
tblJobs.vcApplicationPath,
tblJobs.vcFileName,
tblJobs.intApplicationSize,
tblSalary.vcSalary,
tblCity.vcCityName,
tblJobCategory.vcJobCategory,
tblPositionSchedule.vcJobScheduleType
FROM tblJobs
INNER JOIN tblSalary ON tblJobs.intSalaryID = tblSalary.intSalaryID
INNER JOIN tblPositionSchedule ON tblJobs.intJobSchedule = tblPositionSchedule.intJobScheduleTypeID
INNER JOIN tblJobCategory ON tblJobs.intJobCategory = tblJobCategory.intJobCategoryId
INNER JOIN tblCity ON tblJobs.intCityID = tblCity.intCityId
WHERE
tblJobs.vcJobTitle LIKE '%' + @SearchText + '%'
OR tblJobs.vcBusinessName LIKE '%' + @SearchText + '%'
OR tblJobs.vcJobShortDescription LIKE '%' + @SearchText + '%'
OR tblJobs.vcJobDescription LIKE '%' + @SearchText + '%'
OR tblJobs.vcPositionExperience LIKE '%' + @SearchText + '%'
OR tblJobs.vcJobInquiry LIKE '%' + @SearchText + '%'
And tblJobs.vcJobExpirationDate > getdate()
AND tblJobs.intJobCategory = @CID
AND tblJobs.IntJobSchedule = @SID
ORDER BY
intjobid DESC
END 

View 2 Replies View Related

SQL Statement

Jun 4, 2007

"SELECT * FROM assyProductionData WHERE lineNumber='"&j&"' AND productNumber='"&myRs1("productNumber")&"' AND date='"&myDate&"' AND shift='"&myShift&"'"
 
Can anybody tell me what the "&j&" characters is calling in this string?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved