Help How To ? 7 Conditions For Evry Day Check For All Month

Dec 30, 2007

help how to ? 7 conditions for evry day check for all month

a condition "code block" for evry day in the week
like CASE inside CASE
and How to insert it to #Temp table all







Code Block
CREATE PROC YourProc
@StartDate datetime = NULL,
@EndDate datetime = NULL
AS
SET @StartDate = COALESCE(@StartDate,DATEADD(d,DATEDIFF(d,0,GETDATE()),0))--defaulting to todays date if not supplied
SET @EndDate=COALESCE(@EndDate,DATEADD(m,1,@StartDate))--defaults to 1 month from today

WHILE @StartDate <= @EndDate
BEGIN
SELECT CASE
WHEN DATENAME( dw,@StartDate)='Sunday'

---- for Sunday----for Sunday------------for Sunday----for Sunday------v_un

WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =45 )
THEN 1
WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =51 )
THEN 1
WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =11 )
THEN 2
WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =12)
THEN 2
WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =22 )
THEN 3
WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =23)
THEN 3
WHEN DATENAME( dw,@StartDate)='Sunday' AND
empid IN (SELECT empid FROM v_un WHERE (shift =34)
THEN 5
------------------------END for Sunday----for Sunday
SELECT CASE
WHEN DATENAME( dw,@StartDate)='monday'
---- for monday----for monday------------for monday----for monday----FROM v_1
WHEN DATENAME( dw,@StartDate)='monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =45 )
THEN 1
WHEN DATENAME( dw,@StartDate)='monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =51 )
THEN 1
WHEN DATENAME( dw,@StartDate)='monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =11 )
THEN 2
WHEN DATENAME( dw,@StartDate)='Monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =12)
THEN 2
WHEN DATENAME( dw,@StartDate)='monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =22 )
THEN 3
WHEN DATENAME( dw,@StartDate)='monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =23)
THEN 3
WHEN DATENAME( dw,@StartDate)='monday' AND
empid IN (SELECT empid FROM v_1 WHERE (shift =34)
THEN 5
--------------------------END for monday
SELECT CASE
WHEN DATENAME( dw,@StartDate)='Tuesday'

---- for Tuesdayy----for Tuesday----for Tuesday----for Tuesday----from V_2

WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =45 )
THEN 1
WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =51 )
THEN 1
WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =11 )
THEN 2
WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =12)
THEN 2
WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =22 )
THEN 3
WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =23)
THEN 3
WHEN DATENAME( dw,@StartDate)='Tuesday' AND
empid IN (SELECT empid FROM v_2 WHERE (shift =34)
THEN 5
................................................END for Tuesday
/////////
until
Saturday
.....
WHEN DATENAME( dw,@StartDate)='Saturday' AND
...
THEN ..
END
SET @StartDate=DATEADD(d,1,@StartDate)
END
GO





TNX

View 39 Replies


ADVERTISEMENT

How To Check If Employees Have Full Month - If Not Move To Temp Table

Jan 10, 2008

need help
how to check in table if all the employees have Full month


if it double days fix it

if the employees have less days ! > move to temp table

for eny problem with this employee (check continuity or error) move to temp table !
i have stored procedure that insert employees for next month "Full month"
from start of the month until end of the month
how to check continuity and if i don't give less days OR double days in month
like if the month is 29 days the employee must have 29 not more

for eny problem with this employee move to temp table !

situation 1 employees have less days !
sn empid ShiftDate day
-------------------------------------------------
1 111111 2008-02-01 Tuesday
2 111111 2008-03-02 Wednesday
3 111111 2008-04-03 Thursday
4 111111 2008-03-04 Friday
5 111111 2008-03-05 Saturday
6 111111 2008-03-06 Sunday
7 111111 2008-03-07 Monday
. ----------------------------------------------
8 111111 2008-03-09 Wednesday
9 111111 2008-03-10 Thursday
.......................................................................until end of the month
99 222222 2008-02-01 Tuesday
100 222222 2008-03-02 Wednesday
101 222222 2008-04-03 Thursday
102 222222 2008-03-04 Friday
. ----------------------------------------------
104 222222 2008-03-06 Sunday
105 222222 2008-03-07 Monday
106 22222 2008-03-09 Wednesday
108 22222 2008-03-09 Wednesday
109 22222 2008-03-10 Thursday
.......................................................................until end of the month

situation 2 employee have double days!
sn empid ShiftDate day
-------------------------------------------------
1 111111 2008-02-01 Tuesday
2 111111 2008-03-02 Wednesday
3 111111 2008-04-03 Thursday
4 111111 2008-03-04 Friday
5 111111 2008-03-05 Saturday
6 111111 2008-03-06 Sunday
7 111111 2008-03-07 Monday
8 111111 2008-03-09 Wednesday
9 111111 2008-03-09 Wednesday
10 111111 2008-03-10 Thursday
.......................................................................until end of the month
99 222222 2008-02-01 Tuesday
100 222222 2008-03-02 Wednesday
101 222222 2008-04-03 Thursday
102 222222 2008-03-04 Friday
103 222222 2008-03-04 Friday
104 222222 2008-03-05 Saturday
105 222222 2008-03-06 Sunday
106 222222 2008-03-07 Monday
107 22222 2008-03-09 Wednesday
108 22222 2008-03-09 Wednesday
109 22222 2008-03-10 Thursday
.......................................................................until end of the month

TNX

View 3 Replies View Related

JOIN Efficiency Using Multiple ON Conditions Versus WHERE Conditions

Jan 10, 2008

My question is fairly simple. When I join between two tables, I always use the ON syntax. For example:


SELECT

*
FROM

Users

JOIN UserRoles

ON (Users.UserRoleId = UserRoles.UserRoleId)


No problems there. However, if I then decide to further filter the selection based on some trait of the UserRole, I have two options: I can add the condition as a WHERE statement, or I can add the condition within the ON block.

--Version 1:

SELECT

*
FROM

Users

JOIN UserRoles

ON (Users.UserRoleId = UserRoles.UserRoleId)
WHERE

UserRoles.Active = 'TRUE'


-- Version 2

SELECT

*
FROM

Users

JOIN UserRoles

ON (Users.UserRoleId = UserRoles.UserRoleId

AND UserRoles.Active = 'TRUE')


So, the question is, which is faster/better, if either? The Query Analyzer shows the two queries have the exact same execution plan, which makes sense, since they're both joining the same tables. However, I'm wondering if adding the condition in the ON statement results in fewer rows the JOIN statement initially needs to join up, thus reducing the overall initial size of the results table before the WHERE conditions are applied.

So is there a difference, performance wise? I imagine that if Users had a thousand records, and UserRoles had 10 records, then the JOIN would create a cartesian product of the two tables, resulting in 10,000 records in the table before the WHERE conditions are applied. However, if only three of the UserRoles is set to Active, would that mean that the resulting table, before applying WHERE conditions, would only contain 3000 records?

Thanks for whatever information you can provide.

View 7 Replies View Related

Please Help- How To Add For Evry Row 15 Minutes With Condition

Apr 29, 2008

please need help
i need to create view_circuit like this
for evry row add 15 minutes with condition by station field



Table before
start time@=14:30
ORDER BY 6,9,15
point_collection employee station seated
-----------------------------------------------------------------------------------
start time@=14:30 aaaa 6 station-6
xxxx 9 station-9
nnnnn 9 station-9
cccc 15 station-15
dddd 15 station-15
yyyy 15 station-15
...............................
.........................

Table After
point_collection employee station seated
-----------------------------------------------------------------------------------
14:30 aaaa 6 station-6
14:35 xxxx 9 station-9
14:35 nnnnn 9 station-9
14:40 cccc 15 station-9
14:40 dddd 15 station-9
14:40 yyyy 15 station-9
..................
...................
........
tnx for the help

View 6 Replies View Related

Hide Fname Value Evry Second Row

Apr 20, 2008

need help hide Fname value evry second row
where val =2
i have this table

id fname val
----------------------
11 aaaaa 2
11 aaaaa 1
22 bbbbb 2
22 bbbbb 1
33 ccccc 2
33 ccccc 1
44 ddddd 2
44 ddddd 1


i need to do this
hide Fname value evry second row
where val =2


id fname val
----------------------
11 null 2
11 aaaaa 1
22 null 2
22 bbbbb 1
33 null 2
33 ccccc 1
44 null 2
44 ddddd 1

View 4 Replies View Related

Parameter Selection Of Month, Showing Selected Month And Sum Up To That Month In Another Row

Apr 5, 2008

Hello what I'd like to display the following in a matrix report:

Parameter selected: 3 (March), 2008 (Year)

Monthly TO Summed up
ArtNo March <=March
1210 20,500 50,900
1220 21,200 64,000
1230 15,400 40,300
... ... ...

So, in the rows I have the articles and in the column the selected month via parameter. In another column I need to sum up all monthly values up to the selected month, meaning in this example the sum of jan, feb and mar per article.

View 3 Replies View Related

Analysis :: Calculated Measure To Check Measure Value Updates By Month?

May 13, 2015

In my cube there are two measures which are used in different calculations.Now I'm need to show in report if there any months in data when both or even another one of the measures is not updated (value = 0 or NULL).

how should I create the calculated measure for that?

I have tried in mgmt studio to plan this but I'm in a loop of errors.

View 4 Replies View Related

Import Data From Textfile Evry 2 Hours Automtically

Feb 23, 2001

Hello,

Can somebody please help me with the following problem.

I want to import data from a textfile called "Links.txt" into a SQL-server database called "LinkData". The data in this textfile is separated by pipelines. And this import should be done every 2 hours automatically. How can I make a proces or something in SQL server 7 that will fill the database with the data out of this textfile every 2 hours. Please help me. I really don't know.

greetings

R. Jacobs

View 2 Replies View Related

Import Data From Textfile Evry 2 Hours Automtically WITH DTS

Feb 23, 2001

I want to import data from a textfile called "Links.txt" into a SQL-server database called "LinkData". The data in this textfile is separated by pipelines. And this import should be done every 2 hours automatically. How can I make a proces or something in SQL server 7 that will fill the database with the data out of this textfile every 2 hours. Please help me. I really don't know.

I was planning on using DTS for this Only I really don't know how. I tried it with "Data driven query task" in combination with "Text file (source)" and "Microsoft OLE DB Provider for SQL Server". But when I run it, it gives an error. What am i doing wrong??? Help me please

thanx

View 1 Replies View Related

Help Generate A List Of Hours + Mintes Evry 5 Minte

May 20, 2008

need help Generate a list of hours + mintes evry 5 minte
need create new table of hours + mintes evry 5 minte like this

round_time time_list
--------------------------------------------------------------------------

0 00:00
0 00:05
0 00:10
.................................
........................................

0 00:55
1 01:05
1 01:10
.....................................
.....................................
1 01:55
2 02:00
2 02:05
..................................
.......................................
...........................
23 23:50
23 23:55

TNX

View 3 Replies View Related

T-SQL (SS2K8) :: Get Last Record In A Month When No Guarantee Month Exists Of Unique Dates?

Apr 22, 2015

following table global_usage

ID varchar (contains alphanumeric values,not unique)
Territory (combined with ID unique)
Total_Used int can be null
Date_ date (date of the import of the data)
ID Territory Total_Used Date_
ACASC CAL071287 2014-06-01
ACASC CAL071287 2014-08-01
ACASC CAL071288 2014-09-01

[Code] .....

Now the problem,per month I need the most recent value so I'm expecting

ACASC CAL071287 2014-06-01
ACASC CAL071287 2014-08-01
ACASC CAL071288 2014-09-01
ACASC CAL071288 2014-11-01
ACASC CAL071190 2014-12-14
ACASC CAL071286 2015-01-22
ACASC CAL071165 2015-02-01
ACASC CAL071164 2015-03-01

I've tried a few thing like group,having even row_number() but I keep getting wrong results

View 6 Replies View Related

Transact SQL :: Show (0) Amount For A Month If No Data Exists In The Table For That Month?

Nov 9, 2015

I have two tables Costtable (Id,ResourceId, Amount,Date) and ResourceTable (ResourceId,Name) which shows output as below.

I want to show 0 amount for rest of the name in case of September. For e.g. if rest of the Resources does not appear in cost table they should appear 0 in amount

My Desired output

My current query

SELECT
RG.Id AS Id,
RG.Name AS Name,
ISNULL(SUM(AC.Amount), 0) AS Amount,
RIGHT(CONVERT(varchar(10), AC.[Date], 105), 7) AS [YearMonth]

[Code] ....

View 6 Replies View Related

T-SQL (SS2K8) :: Convert Number Of Month In Integer Into How Many Year And Month

Sep 10, 2014

This is my table and data

CVID | WorkExperience
--------------------------------
2838736
68181101
96568122
1135484

I need to convert into this result

CVID | WorkExperience
--------------------------------
283873 years
681818 years 5 months
9656812 years 2 months
1135484 months

View 5 Replies View Related

Transact SQL :: Displaying Sales Data In A Month By Month Grid

Aug 11, 2015

Most of the data is in one table. 

Company 1-Jan 1-Feb 1-Mar 1-Apr
RSP RSP RSP RSP
NON-RELO $295 1 $0 0 $1,400 7 $0 0 $1,195 4 $0 0 $4,700 8 $0 0
AMERICAN ESCROW & CL//AECC $2,650 4 $0 0 $3,720 8 $0 0 $2,339 4 $0 0 $2,460 2 $0 0
American Internation//AIRCO $9,131 30 $2,340 9 $10,927 35 $2,340 9 $9,142 31 $2,600 10 $18,406 54 $3,900 15
American Internation//AIR $20,611 63 $1,820 8 $23,892 75 $1,040 4 $35,038 111 $3,120 12 $3,778 16 $1,560 6
American Internation//Ab $64,248 206 $6,240 24 $59,800 187 $5,200 20 $87,115 264

I did something similar doing just record counts but this is far more complicated. I'm at a loss that this is even possible.

 SUM(CASE datepart(month, tbFile.openedDate) WHEN 1 THEN 1 ELSE 0 END) AS 'January', 

View 2 Replies View Related

Help Split List Of Email Add Comma For Evry Email

May 12, 2008

need help
split list of email add comma for evry email
i have tabe "tblLogin" and in this table i have field emall
like this

emall
-----------------------------------------
aaa@hhhh.mm
nnn@hhhh.mm
mmm@hhhh.mm

need to do ilke this



Code Snippet
@list_email = (SELECT emall FROM tblLogin)

--------------------------i get this
-----------------------@list_email=aaa@hhhh.mm ; nnn@hhhh.mm ; mmm@hhhh.mm

@recipients = @list_email










Code Snippet

IF EXISTS( SELECT * FROM [db_all].[dbo].[taliB] )



BEGIN

DECLARE @xml NVARCHAR(MAX)DECLARE @body NVARCHAR(MAX)

SET @xml =CAST(( SELECT

FirstName AS 'td','',

LastName AS 'td','' ,

Date_born AS 'td','' ,

Age AS 'td','' ,

BirthdayToday AS 'td','' ,

BirthdayThisWeek AS 'td'

FROM [Bakra_all].[dbo].[taliB] ORDER BY LastName FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))

SET @body ='<html><H1 align=center>aaaaaaaaaaaaaaaaaaaaaa</H1><body ><table border = 1 align=center dir=rtl>

<tr>

<td>name</td>

<td>fname</td>

<td>date</td>

<td>age</td>

<td>aaaaaaaaa</td>

<td>bbbbbbbbbbbbbbb</td>

</tr>'

SET @body = @body + @xml +'</table></body></html>'

EXEC msdb.dbo.sp_send_dbmail

@recipients =N'rrr@iec.co.il',

@copy_recipients='rrrrr@iec.co.il',

@body = @body,

@body_format ='HTML',

@subject ='ggggggggggggggggggggg',

@profile_name ='ilan'

END

ELSE

print 'no email today'

View 1 Replies View Related

Get Last Day Of Month For Agiven Month And Year

Aug 2, 2002

Does anyone know how I can get last day of month
if I pass a function a given month and and given year.
@Month = 2
@Year = 2004
The result I would need is 29 because there are 29 in
the month of February in the 2004.
Any help on this is greatly appreciated.
Kellie

View 1 Replies View Related

Data Access :: How To Check All Connection Automatically During Routine Check By Using Batch File

May 20, 2015

I have multiple ODBC connection and how to check all connection automatically during routine check by using batch file.

View 5 Replies View Related

SQL 2012 :: Use Date Trunc Or Date Function To Select Date Range For Month On Month View

Jul 29, 2015

My goal is to select values from the same date range for a month on month view to compare values month over month. I've tried using the date trunc function but I'm not sure what the best way to attack this is. My thoughts are I need to somehow select first day of every month + interval 'x days' (but I don't know the syntax).In other words, I want to see

Select
Jan 1- 23rd
feb 1-23rd
march 1-23rd
april 1-23rd
,value
from
table

View 9 Replies View Related

Month-to-month Function

Sep 10, 2007

Hi I trying to find a way to determine the number of working days per month starting from the current date to the last day of the current month.And within the same store procedure determine the number of working days as normal (each month is independent from the next). For example: The store procedure is executed

September:
@CurrentDate = 9/10/2007
@EndDate = last working day 9/30/2007

Total# of working days = 15

October:
@CurrentDate = 10/1/2007
@EndDate = last working day 10/31/2007

Total# of working days = 23

November:
@CurrentDate = 11/1/2007
@EndDate = last working day 11/30/2007

Total# of working days = 22
etc.
Any ideas of how i can approch this?

Thanks in advance.

View 3 Replies View Related

Conditions, Expressions

Aug 7, 2007

I have a table
CREATE TABLE [dbo].[CmnLanguage]( [Id] [char](2) NOT NULL CONSTRAINT PkCmnLanguage_Id PRIMARY KEY, [EnglishName] [varchar](26) NOT NULL, [NativeName] [nvarchar](26) NOT NULL, [DirectionType] [smallint] NOT NULL, [IsVisible] [bit] NOT NULL, [CreatedDateTime] [datetime] NOT NULL DEFAULT GETDATE(), [ModifiedDateTime] [datetime] NULL)
We will use these 3 queries
select * from CmnLanguage where IsVisible = 0select * from CmnLanguage where IsVisible = 1select * from CmnLanguage
I want to make a method which handles these queries.
But at the back end on Stored Procedures
We have to write 3 queries
Which I don't want to do.
I want to minimize the queries and conditions
and want to just write one for these 3
Can any one do it?

View 2 Replies View Related

HELP....&#34;OR&#34; Conditions In SQL Statements

May 31, 2000

Folks,

I'm having some real problems using the OR condition in a very simple SQL statement and could use your help or insight on where the problem lies, or perhaps a workaround.

I have a large flat table in a SQL 7 database with 10 million + records called "HISTORY". I have not installed either service pack 1 or 2. I'm attempting to run a query that references the following four fields which are all non-clustered keys:

EQUIPMENT_NO TEXT 12
CHASSIS_IN TEXT 12
CHASSIS TEXT 12
SVC_DATE_TIME SMALLDATETIME

Here's the SQL statement:

SELECT * FROM HISTORY WHERE (HISTORY.EQUIPMENT_NO = 'XYZ123' OR HISTORY.CHASSIS = 'XYZ123' OR HISTORY.CHASSIS_IN = 'XYZ123') AND SVC_DATE_TIME >= '01/15/00 00:00:00 AM' AND SVC_DATE_TIME <= '02/28/00 23:59:59 PM'
ORDER BY EQUIPMENT_NO

This query takes 11 min. 5 sec. inder the Query Analyzer and ultimately returns the 31 desired records.

If you remove the SVC_DATE_TIME criteria, about 350 records are returned in a matter of seconds. I've also tried variations on the date syntax such as '01/15/00', etc. with no change in the amount of time to execute.

Other queries such as a simple AND condition combining EQUIPMENT_NO and SVC_DATE_TIME are snappy.

Are there known problems/bugs with "OR" conditions in queries that anyone is aware of, particularly with parentheses; am I composing this query incorrectly? Is there some alternate syntax that would work as expected? I can't see where the query shouldn't execute quickly as expected, particularly with all indexed fields involved. I'm stumped! Lend me your expertise. Thanks much.

Clark R. Farabaugh, Jr.
Financial Systems Analyst
VIT
Norfolk, VA

View 8 Replies View Related

Regarding Aggregate Conditions ..

Nov 29, 2007

Hai frns small help needed.


I have a table called sample and i have the following requirement. i.e i need sum(credit) group by ssn no.

One special condition is as follows:


For each distinct ssn if "flag" has the same CX value,then out of all the records with the same CX value, the highest "credit" value is added to the sum for that "ssn" and the rest are ignored.
If while adding "credit" to the sum and if "credit" value is equal to zero then "sum" value is used for summing else "credit" value is used.
Can any one help me out in trying this logic. I have tried but i could'nt able embed the conditions inbetween the Sql statetment.

Here is the query is used

select * from sample

idssncreditflagsem
11010C90
21014C93
31014.5C92
41013.5C11
51024.2C33
61030C12


select ssn,flag,sum(case credit when 0 then sem else credit end) as sum from sam2
group by ssn,flag


ssn flag sum_val
101C13.5
103C12.0
102C34.2
101C98.5

The above output is wrong one.


Expected output

101 4.5+3.5=8.0
102 4.2
103 2.0


Any help would be appreciated

Regards,

View 5 Replies View Related

Where Clause With Conditions

Mar 19, 2012

Code:
Drop table #table
Drop table #table_with_groupid
-- Prepare test data
CREATE TABLE #table
([Admissions_key] bigint NOT NULL PRIMARY KEY,
MRN nvarchar(10) NOT NULL,

[Code] ....

How can I compare dates with conditions. I only want to Mark C where the difference between adm_datetime and prevsep_datetime is <= 1 otherwise E as well

where datediff(MINUTE,tg.adm_datetime,tg.pre_sep_date)< =1 ??

is it correct ? where should I put this to implement correctly ?

View 1 Replies View Related

Case When Conditions

Oct 14, 2014

I have the following:

MAX(Vernum) AS test,
MAX(Case WHEN A2.AttrID = 2 AND A2.DefID = 10057945 THEN A2.ValStr END) AS TYPE_DOCUMENT

This works not perfect. In many cases I have more then one row and my query takes the max value of column Valstr. Thats is not exactly what I want. I'd like to have the value of Column Valstr of the row where column Vernum has the maximum value.

I've tried many things like:

MAX(Vernum) AS test,
MAX(Case WHEN A2.AttrID = 2 AND A2.DefID = 10057945 AND A2.Vernum=test THEN A2.ValStr END) AS TYPE_DOCUMENT

OR

MAX(Vernum) AS test,
MAX(Case WHEN A2.AttrID = 2 AND A2.DefID = 10057945 AND A2.Vernum=MAX(A2.Vernum) THEN A2.ValStr END) AS TYPE_DOCUMENT

View 1 Replies View Related

Multiple AND Conditions

Sep 12, 2006

Hi All.

Is there a way to have multiple AND conditions on the same field in a database.

EXAMPLE

SELECT * FROM tbl
WHERE field1 = 1 AND field1 = 2 AND field1 = 5

Thanks

View 9 Replies View Related

Can We Put 2 Conditions In Inner Join

Oct 24, 2006

pls:
1/ can we do it this way:
inner join Table2 ON table1.fld1=table2.fld21 AND table1.fld12=table2.fld22
2/also:
what s the difference between join , iner join and left join
Thanks .

View 4 Replies View Related

Procedure Has Many If Else Conditions

Jul 16, 2007

ALTER PROC usp_t_insup_cpa1

@Idint,
@SupervisorIdint,
@BookmarkerIdint,
@PreparerIdint,
@FirmNovarchar(20),
@FirmNamevarchar(30),
@FirstNamevarchar(20),
@MiddleNamevarchar(20),
@LastNamevarchar(20),
@TaxYearvarchar(20),
@TaxSoftwarevarchar(20),
@HomePhonevarchar(20),
@WorkPhonevarchar(20),
@Faxvarchar(20),
@PrimaryEmailvarchar(30),
@SecondaryEmailvarchar(30),
@CountryIdint,
@Statevarchar(20),
@Zipcodevarchar(20),
@Statusint,
@OperatorChar(1) = '',
@RESULTINT OUTPUT
-------------------------
AS

IF @Operator = 'I'
BEGIN

IF NOT EXISTS(SELECT * FROM CPA WHERE PrimaryEmail=@PrimaryEmail or PrimaryEmail=@SecondaryEmail or SecondaryEmail=@PrimaryEmail or SecondaryEmail=@SecondaryEmail )
BEGIN
--select * from o_login
Begin transaction InsCPA

INSERT INTO CPA(SupervisorId,BookmarkerId,PreparerId,FirmNo,FirmName,FirstName,MiddleName,LastName,TaxYear,TaxSoftware,HomePhone,WorkPhone,Fax,PrimaryEmail,SecondaryEmail,CountryId,State,Zipcode,Status)
VALUES(@SupervisorId,@BookmarkerId,@PreparerId,@FirmNo,@FirmName,@FirstName,@MiddleName,@LastName,@TaxYear,@TaxSoftware,@HomePhone,@WorkPhone,@Fax,@PrimaryEmail,@SecondaryEmail,@CountryId,@State,@Zipcode,@Status)

--Error handling
IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN InsCPA
SET @RESULT = 0
END
ELSE
BEGIN
--DECLARE @ID1 INTEGER
-- Returns 1 to the calling program to indicate success.
COMMIT TRAN InsCPA
SET @RESULT = 1
END
END
ELSE
BEGIN
-- Return 2 to the calling program to indicate record already exists.
set @RESULT = 2
END
END

ELSE IF(@Operator='U')
BEGIN
declare @pemail as varchar(30)
declare @semail as varchar(30)
declare @firm as varchar(20)
select @pemail=PrimaryEmail,@semail=SecondaryEmail,@firm=FirmNo from CPA WHERE Id = @Id
--select * from CPA

if(@pemail=@PrimaryEmail) or(@semail=@PrimaryEmail)--or((@semail=@SecondaryEmail)and (@semail=@PrimaryEmail)))
begin

print 'prim1'
if(@semail=@SecondaryEmail)or (@pemail=@SecondaryEmail)
begin
print 'sec1'
if(@firm=@FirmNo)
begin
print'firm'
BEGIN TRANSACTION UpdateCPA
UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id
UPDATE EMPLOYEE
SET FirmNo=@FirmNo
WHERE FirmNo=@firm


IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN UpdateCPA
SET @RESULT = 0

END
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'1'
COMMIT TRAN UpdateCPA
SET @RESULT = 1

END
END
else
begin
IF NOT EXISTS(SELECT * FROM CPA WHERE FirmNo=@FirmNo)
BEGIN
print'fd'
BEGIN TRANSACTION UpdateCPA
UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id
UPDATE EMPLOYEE
SET FirmNo=@FirmNo
WHERE FirmNo=@firm
IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN UpdateCPA
SET @RESULT = 0

END
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'1'
COMMIT TRAN UpdateCPA
SET @RESULT = 1

END
end
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'4'
--COMMIT TRAN UpdateCPA
SET @RESULT = 4

END
end
end
else
begin
IF NOT EXISTS(SELECT * FROM CPA WHERE PrimaryEmail=@SecondaryEmail or SecondaryEmail=@SecondaryEmail)
BEGIN
if(@firm=@FirmNo)
begin
BEGIN TRANSACTION UpdateCPA
UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id
UPDATE EMPLOYEE
SET FirmNo=@FirmNo
WHERE FirmNo=@firm

IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN UpdateCPA
SET @RESULT = 0

END
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'1'
COMMIT TRAN UpdateCPA
SET @RESULT = 1

END
END
else
begin
IF NOT EXISTS(SELECT * FROM CPA WHERE FirmNo=@FirmNo)
BEGIN
BEGIN TRANSACTION UpdateCPA
UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id
UPDATE EMPLOYEE
SET FirmNo=@FirmNo
WHERE FirmNo=@firm
IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN UpdateCPA
SET @RESULT = 0

END
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'1'
COMMIT TRAN UpdateCPA
SET @RESULT = 1

END
end
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'44'
--COMMIT TRAN UpdateCPA
SET @RESULT = 4

END
end
/*
--select * from o_login
Begin transaction InsCPA

UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id
--Error handling
IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN InsCPA
SET @RESULT = 0
END
ELSE
BEGIN
--DECLARE @ID1 INTEGER
-- Returns 1 to the calling program to indicate success.
print'11'
COMMIT TRAN InsCPA
SET @RESULT = 1
END*/
END
ELSE
BEGIN
print 'sec same'
-- Return 2 to the calling program to indicate record already exists.
set @RESULT = 3
END
end
end
else
begin
IF NOT EXISTS(SELECT * FROM CPA WHERE PrimaryEmail=@PrimaryEmail or SecondaryEmail=@PrimaryEmail)
BEGIN
/*--select * from o_login
Begin transaction InsCPA

UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id
--Error handling
IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN InsCPA
SET @RESULT = 0
END
ELSE
BEGIN
--DECLARE @ID1 INTEGER
-- Returns 1 to the calling program to indicate success.
print'111'
COMMIT TRAN InsCPA
SET @RESULT = 1
END*/
if(@firm=@FirmNo)
begin
BEGIN TRANSACTION UpdateCPA
UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id

UPDATE EMPLOYEE
SET FirmNo=@FirmNo
WHERE FirmNo=@firm

IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN UpdateCPA
SET @RESULT = 0

END
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'1'
COMMIT TRAN UpdateCPA
SET @RESULT = 1

END
END
else
begin
IF NOT EXISTS(SELECT * FROM CPA WHERE FirmNo=@FirmNo)
BEGIN
BEGIN TRANSACTION UpdateCPA
UPDATE CPA
SET SupervisorId=@SupervisorId,
BookmarkerId=@BookmarkerId,
PreparerId=@PreparerId,
FirmNo=@FirmNo,
FirmName=@FirmName,
FirstName=@FirstName,
MiddleName=@MiddleName,
LastName=@LastName,
TaxYear=@TaxYear,
TaxSoftware=@TaxSoftware,
HomePhone=@HomePhone,
WorkPhone=@WorkPhone,
Fax=@Fax,
PrimaryEmail=@PrimaryEmail,
SecondaryEmail=@SecondaryEmail,
CountryId=@CountryId,
State=@State,
Zipcode=@Zipcode,
Status=@Status
WHERE Id = @Id

UPDATE EMPLOYEE
SET FirmNo=@FirmNo
WHERE FirmNo=@firm
IF @@ERROR <> 0
BEGIN
-- Returns 0 to the calling program to indicate failure.
ROLLBACK TRAN UpdateCPA
SET @RESULT = 0

END
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'1'
COMMIT TRAN UpdateCPA
SET @RESULT = 1

END
end
ELSE
BEGIN
-- Returns 1 to the calling program to indicate success.
print'2'
--COMMIT TRAN UpdateCPA
SET @RESULT = 2

END
end
END
ELSE
BEGIN
print 'prim same'
-- Return 2 to the calling program to indicate record already exists.
set @RESULT = 2
END
end
end

Above procedure has many if else conditions
Is there any way to write
procs other than this process

Malathi Rao

View 1 Replies View Related

Playing About With The AND And OR Conditions

Jul 26, 2007

Hi folks, basically I'm looking for this sort of structure

WHERE (caseA AND caseB) OR (caseC AND caseD) OR (CaseA AND caseD)

but I can't seem to be able to group the AND conditions together any time I try put brackets in SQL Server Enterprise manager removes them on me,

any help would be great,

thanks

View 1 Replies View Related

Where Conditions, Encryption

May 5, 2007

1. Are stored procedures WITH ENCRYPTION slower than the ones withoutencryption?2. Should i put most restrictive conditions first or last in WHERE? Inwhich order does MSSQL execute conditions? Or MSSQL determents whatwould be best and does not bother with the way i sorted conditions?for example:SELECT *FROM [users]WHERE[user_id] = 1 AND[baned] = 0Is "[user_id] = 1" or "[baned] = 0" going to be executed first?

View 2 Replies View Related

Count If Conditions Met

Jul 20, 2005

I am trying to do a summary SQL query. I have 3 fields. If one filed isnull and the other is not null, I want to count how many records thereare. I also want to count the opposite way then count both fields ifthey are both not null. Can I do this within the same query? Helpappreciated.Thanks,Steve*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 2 Replies View Related

Not All Where Conditions Required

Mar 17, 2008

I am trying to do a select with the closest match.



Code Snippet


CREATE TABLE [#Person]

(

[PersonId] tinyint IDENTITY(1,1) NOT NULL

,[Height] char(2) NOT NULL

,[Weight] char(3) NOT NULL

,[Age] varchar(3) NOT NULL

,[HairColor] varchar(7) NOT NULL

,[EyeColor] varchar(7) NOT NULL

);


INSERT INTO [#Person] ([Height],[Weight],[Age],[HairColor],[EyeColor])

VALUES ('71', '150', '23', 'Brown', 'Blue');

INSERT INTO [#Person] ([Height],[Weight],[Age],[HairColor],[EyeColor])

VALUES ('70', '190', '22', 'Blonde', 'Brown');

INSERT INTO [#Person] ([Height],[Weight],[Age],[HairColor],[EyeColor])

VALUES ('69', '140', '20', 'Black', 'Brown');

INSERT INTO [#Person] ([Height],[Weight],[Age],[HairColor],[EyeColor])

VALUES ('65', '150', '21', 'Brown', 'Green');


SELECT * FROM [#Person]

WHERE

([Height] > '66' AND [Height] < '72')

AND ([Weight] > '150' OR [Weight] < '180')

AND ([Age] > '20' OR [Age] < '25')

AND ([HairColor] IN ('Brown', 'Blonde', 'Black'))

AND ([EyeColor] IN ('Blue', 'Brown', 'Green'));


DROP TABLE [#Person];




This simple example works great. But what if I wanted everybody who met 4 of the 5 conditions? I tried to think of a counting solutions, and then order by the count but I could quite get there. Any help would be greatly appreciated. My live data is actual sales records with 20 some odd record types. I am hoping any solutions I find will scale well.

View 8 Replies View Related

How Do I Implement If Then Else Conditions

May 28, 2007

Hi All,



I'm very new to Integration Services. Self Learned this ETL tool based on my prior ETL tool knowledge.



Can you tell me how do write IF Then Else conditions for every column in my source and redirect to a single output?





Hey correction here ... i'm using flat file as my source





Thanks in Advance,

Suresh N

View 7 Replies View Related

Conditions With Trigger

Dec 5, 2007

Hi,

I want to create a trigger that that is invoked when a certain condition is fulfilled. For instance:

I have 2 tables, PS and US with similar table structure. PS table contains a column called 'status'. Whenever the status column is updated from 2 to either 23, 24, 25 or 26, a new row, which contains the same data within the updated row of PS, will be inserted into the table US.

Can this be done? Thanks in advance.

View 4 Replies View Related







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