Showing posts with label guys. Show all posts
Showing posts with label guys. Show all posts

Thursday, March 22, 2012

Check if exist

Hi guys help please..is there a function in MS SQL that check if a particular value exist in a row and would return a boolean value base from what found, Return True if it found something and False if it does not found one. I've try the EXISTS function but I cant get the rigth syntax..Any help will be greatly appreciated!

OR Maybe you can help me directly with my problem. I want to check first in my Table 1 with 3 columns if value X exists in column 1 and if X exists UPDATE that column with value Y and if value X does not exists INSERT something in the Table 1. Any suggestion or Comments will be greatly appreciated!Hi

Post what you've got for your exists syntax. It should merely require some tweaking.|||Here it is.
EXISTS(select Sales_Date from CFREE_Sales where Sales_Date = '8/31/2007 12:00:00 AM')|||Try:
IF EXISTS(select Sales_Date from CFREE_Sales where Sales_Date = '20070831') BEGIN
PRINT 'It exists'
END
ELSE BEGIN
PRINT 'It does not exist'
END What is the result|||Yah...Thats what I need..Thanks a lot!|||An alternative to if exists (select * from #t1 where c1='x') begin
update #t1 set c2=c2+100 where c1='x'
end
else begin
insert into #t1 values ('x',100)
endisupdate #t1 set c2=c2+100 where c1='x'
if @.@.rowcount=0 begin
insert into #t1 values ('x',100)
end|||update #t1 set c2=c2+100 where c1='x'
if @.@.rowcount=0 begin
insert into #t1 values ('x',100)
endbingo! :beer:

Sunday, March 11, 2012

Check constraints on clustered columns

Hi guys 'n gals, I'm having an issue wrapping my head around a check constraint that I need to set on a table in my database.

Table: OnCall
Columns: OnCall_PKey (identity), Person_Key, StartDate, EndDate

When a new record is entered, I need a check constraint to make sure that the person entered does not already exist in the table with an overlapping time period:

If in the new record, the start date or the end date fall between the start date and the end date for an existing record having the person key in the new record then the record fails the check.

Example:
One existing data row from my table:
1496, 06/12/2007, 12/12/2007

I try to add:
1496, 09/12/2007, 15/12/2007

The record fails because the new date range overlaps the existing record in the table. No person can have overlapping time periods, however, a person can have multiple time slots in the table, it's just that none of the time slots may overlap.

Any pointers, will be gratefully received.What about defining a trigger on the table ?

Thursday, March 8, 2012

Check available Time procedure

Hey Guys,
I hope someone can help on here with this. I have this Database where techs are scheduled and dispatched to perform tasks based on skus. What I am trying to achieve is finding the first available Tech based on their schedule and the appointments table.
Example User enters today's date and 5:30 AM and the search for all available techs to perform that task

the tables ddl is
USE [Schedule]
GO
/****** Object: Table [dbo].[AllDays] Script Date: 05/31/2006 01:13:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[AllDays](
[ID] [int] NOT NULL,
[DayString] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_WorkingDays] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
USE [Schedule]
GO
/***Appointments Table where trouble is *****
/****** Object: Table [dbo].[Appointments] Script Date: 05/31/2006 01:17:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Appointments](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Customer_ID] [int] NOT NULL,
[Tech_ID] [int] NOT NULL,
[StartTime] [datetime] NOT NULL,
[EndTime] [datetime] NOT NULL,
[App_Date] [datetime] NOT NULL,
[Created_By] [int] NOT NULL,
[Date_Created] [datetime] NOT NULL,
[Sku_ID] [int] NOT NULL,
[Comment_ID] [int] NOT NULL,
CONSTRAINT [PK_TechsShifts] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
USE [Schedule]
GO
ALTER TABLE [dbo].[Appointments] WITH CHECK ADD CONSTRAINT [FK_Appointments_Comments] FOREIGN KEY([Comment_ID])
REFERENCES [dbo].[Comments] ([ID])
GO
ALTER TABLE [dbo].[Appointments] WITH CHECK ADD CONSTRAINT [FK_Appointments_Techs] FOREIGN KEY([Tech_ID])
REFERENCES [dbo].[Techs] ([ID])

USE [Schedule]
GO
/****** Object: Table [dbo].[Schedule] Script Date: 05/31/2006 01:19:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Schedule](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Tech_ID] [int] NOT NULL,
[AllDayID] [int] NOT NULL,
[ShiftStartTime] [datetime] NOT NULL,
[ShiftEndTime] [datetime] NOT NULL,
CONSTRAINT [PK_Schedule] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
USE [Schedule]
GO
ALTER TABLE [dbo].[Schedule] WITH CHECK ADD CONSTRAINT [FK_Schedule_AllDay] FOREIGN KEY([AllDayID])
REFERENCES [dbo].[AllDays] ([ID])

Plus the Techs Table which holds their ID's names etc
I have a snapshot (http://webdivisions.net/images/relation.gif) of the relationship posted here if that can help

Thanks for any inputDefine "first available tech".
Does an appointment have to fall completely within a single tech's shift?
Can an appointment span a day?
And why are you using varchar to store date values?

Look, a basic query would look like this:

select top 1 Schedule.Tech_ID
from Schedule
inner join Appointments
on Schedule.ShiftStartTime <= Appointments.StartTime
and Schedule.ShiftEndTime <= Appointments.EndTime
where not exists
(select *
from Appointments Committed
where Commited.TechID = Schedule.Tech_ID
and ((Committed.ShiftStartTime BETWEEN Appointments.StartTime and Appointments.EndTime)
or
(Committed.ShiftEndTime BETWEEN Appointments.StartTime and Appointments.EndTime)
or
(Appointments.StartTime BETWEEN Committed.ShiftStartTime and Committed.ShiftEndTime)))|||Thanks for the reply blindman,
What I meant by first tech can be best explained with this scenario.
End user selects date as 06/02/2006 at 10:00 AM then search. the query should return all available techs for that date and period of time and the closest time available if 10:00 AM is not available on that day.
Example*******************
Tech available from date available
Tech1 10:00 AM 06/02/2006
Tech2 11:00 AM 06/02/2006
tech2 9:00 AM 06/02/2006
************************
now as for your question
>Does an appointment have to fall completely within a single tech's shift?
Yes, all techs will be required to reschedule their appointment if they cant finish them on day assigned.
Can an appointment span a day?
No they shouldnt, its just not within the nature of the business to do this.
And why are you using varchar to store date values?
I cant see where you seen that. I know varchar for dates will complicate things for me so I stayed away from doing that.

I hope that answers your questions.

Thanks for your time|||...
And why are you using varchar to store date values?
I cant see where you seen that. I know varchar for dates will complicate things for me so I stayed away from doing that.

"[DayString] [varchar](20) "??

Will the logic I gave you in my sample code work for your situation?|||"[DayString] [varchar](20) "??
Oh this table hold an integer representing the day and DayString is the day itself.
**************************
ID DayString
1 Sunday
2 Monday
**************************
I tried to run the SQL the following

select top 1 Schedule.Tech_ID
from Schedule
inner join Appointments
on Schedule.ShiftStartTime <= Appointments.StartTime
and Schedule.ShiftEndTime <= Appointments.EndTime
where not exists
(select *
from Appointments Committed
where Committed.Tech_ID = Schedule.Tech_ID
and ((Committed.StartTime BETWEEN Appointments.StartTime and Appointments.EndTime)
or
(Committed.EndTime BETWEEN Appointments.StartTime and Appointments.EndTime)
or
(Appointments.StartTime BETWEEN Committed.StartTime and Committed.EndTime)))

the result was no records. Am I missing something here?
Thanks for your help|||Logic error. Should have been:
select top 1 Schedule.Tech_ID
from Schedule
inner join Appointments
on Schedule.ShiftStartTime <= Appointments.StartTime
and Schedule.ShiftEndTime >= Appointments.EndTime
.........to find shifts that bracket the appointments.|||Thanks Blindman :-)
After the I changed the script to what you recommended, The statements returned one row.
Now the stupid question, Is it possible to return the top 1 then the closest available techs as well?
IE, If user enters 12/02/2007 10:30 AM and we have tech1 who starts at 9:30 AM on that day and have no appointment but tech2 starts 12:00 PM. and have an appointment starting 12/02/2007 1:30 PM and ending 12/02/2007 4:00 PM. is it possible to list tech2 with his/her availablity. this way the user doesnt have to go back and query the database again by changing date and time.

second stupid question and that is related to my lack of experience in SQL is how can send this SP the date and time to look for.

Thank you very much for your help.|||In answer to your first question, just about anything can be done in SQL. But you are getting into some fairly complex business logic that is particular to your application. It will require a substantial amount of effort in requirements gathering and programming to get this right. You either need to get educated on SQL fast, or hire a contractor to do the work for you.

To answer your second question, the datetime value can be sent to the stored procedure as a parameter. Please read about stored procedures in Books Online.|||Thank you for all your help blindman
You have been great

I'll be hitting the book store today!|||Hit Books Online first. It's free.

Wednesday, March 7, 2012

Cheapest way to purchase SQL Reporting Services

Within my department we have 1 copy of of vb studio.net standard and 2 copies
of vb studio.net enterprise and run sql server 2000.
One of the guys is writing a system which I have to report on using SQL
Reporting Services. As I don't have any .net product, do I have to purchase a
.net product to then get a development edition of SQL Reporting Services to
write any reports etc.
Looking for the cheapest way to be able to use SQL Reporting Services as I
work in the NHS (lucky me).
Any help will be much appreciated.
Thanks, MarkYour SQL license gives you RS. All you need to develop report is a copy of
VS. The cheapest way to aquire it is VB.net standard.
=?Utf-8?B?bWFya19tZW56aWVz?= <mark_menzies@.discussions.microsoft.com>
wrote in news:DC6ABF54-CFC9-417F-A898-1DB7FCB21549@.microsoft.com:
> Within my department we have 1 copy of of vb studio.net standard and 2
> copies of vb studio.net enterprise and run sql server 2000.
> One of the guys is writing a system which I have to report on using
> SQL Reporting Services. As I don't have any .net product, do I have to
> purchase a .net product to then get a development edition of SQL
> Reporting Services to write any reports etc.
> Looking for the cheapest way to be able to use SQL Reporting Services
> as I work in the NHS (lucky me).
> Any help will be much appreciated.
> Thanks, Mark
>|||Also, RS 2005 comes with a version of VS so no extra purchase is required.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Asher_N" <compguy666@.hotmail.com> wrote in message
news:Xns970F5808B7AFDcompguy666hotmailcom@.207.46.248.16...
> Your SQL license gives you RS. All you need to develop report is a copy of
> VS. The cheapest way to aquire it is VB.net standard.
> =?Utf-8?B?bWFya19tZW56aWVz?= <mark_menzies@.discussions.microsoft.com>
> wrote in news:DC6ABF54-CFC9-417F-A898-1DB7FCB21549@.microsoft.com:
>> Within my department we have 1 copy of of vb studio.net standard and 2
>> copies of vb studio.net enterprise and run sql server 2000.
>> One of the guys is writing a system which I have to report on using
>> SQL Reporting Services. As I don't have any .net product, do I have to
>> purchase a .net product to then get a development edition of SQL
>> Reporting Services to write any reports etc.
>> Looking for the cheapest way to be able to use SQL Reporting Services
>> as I work in the NHS (lucky me).
>> Any help will be much appreciated.
>> Thanks, Mark
>>
>

Friday, February 24, 2012

Chart Question: Number of Bars on X-axis

Hi Guys,
Is there any way, we can set the number of Bars on X-axis per Page (in a
Column Chart) in Report Designer?
All I want to do is set no of Bars per page so that a new page is created if
the number of bars on the X-axis exceeds the given value..
Any help is appreciated..
Regards
Raj ChidipudiThis is not natively supported in RS2000.
Depending on your actual data, you may be able to use filters on the first
chart and dynamically show/hide additional charts (with page breaks) if the
number of bars is too high for the first chart.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Raj Chidipudi" <someone@.email.com> wrote in message
news:Ok9QsdbmEHA.596@.TK2MSFTNGP11.phx.gbl...
> Hi Guys,
> Is there any way, we can set the number of Bars on X-axis per Page (in a
> Column Chart) in Report Designer?
> All I want to do is set no of Bars per page so that a new page is created
if
> the number of bars on the X-axis exceeds the given value..
> Any help is appreciated..
> Regards
> Raj Chidipudi
>

Friday, February 10, 2012

Changing Type of Stored Procedure

Hi guys...
I have some stored procedures which I would like changed from "User" to
"System". Does anyone know the fast way to do this?
Thanks,
ForchI'm curious... why do you need to do this?
"Forch" <forch@.somethere.com> wrote in message
news:u2URsqUAEHA.3400@.tk2msftngp13.phx.gbl...
> Hi guys...
> I have some stored procedures which I would like changed from "User" to
> "System". Does anyone know the fast way to do this?
> Thanks,
> Forch
>|||Because one database has all of these stored procedure that start with"dt_"
and are shown as "system", while the exact duplicate database has the same
"dt_" stored procedures and they are "user" stored procedures.
Cheers,
Forch
"Armando" <blba2k@.yahoo.com> wrote in message
news:ObB6PwUAEHA.448@.TK2MSFTNGP11.phx.gbl...
> I'm curious... why do you need to do this?
> "Forch" <forch@.somethere.com> wrote in message
> news:u2URsqUAEHA.3400@.tk2msftngp13.phx.gbl...
>|||Those are the result of someone using the Diagram tool in EM. They're
generated
as system procs. I've never seem them listed as user procs. Personally,
I wouldn't
touch them.
"Forch" <forch@.somethere.com> wrote in message
news:em4kNJVAEHA.3220@.TK2MSFTNGP10.phx.gbl...
> Because one database has all of these stored procedure that start
with"dt_"
> and are shown as "system", while the exact duplicate database has the same
> "dt_" stored procedures and they are "user" stored procedures.
> Cheers,
> Forch
>
> "Armando" <blba2k@.yahoo.com> wrote in message
> news:ObB6PwUAEHA.448@.TK2MSFTNGP11.phx.gbl...
to
>

Changing Type of Stored Procedure

Hi guys...
I have some stored procedures which I would like changed from "User" to
"System". Does anyone know the fast way to do this?
Thanks,
ForchI'm curious... why do you need to do this?
"Forch" <forch@.somethere.com> wrote in message
news:u2URsqUAEHA.3400@.tk2msftngp13.phx.gbl...
> Hi guys...
> I have some stored procedures which I would like changed from "User" to
> "System". Does anyone know the fast way to do this?
> Thanks,
> Forch
>|||Because one database has all of these stored procedure that start with"dt_"
and are shown as "system", while the exact duplicate database has the same
"dt_" stored procedures and they are "user" stored procedures.
Cheers,
Forch
"Armando" <blba2k@.yahoo.com> wrote in message
news:ObB6PwUAEHA.448@.TK2MSFTNGP11.phx.gbl...
> I'm curious... why do you need to do this?
> "Forch" <forch@.somethere.com> wrote in message
> news:u2URsqUAEHA.3400@.tk2msftngp13.phx.gbl...
> > Hi guys...
> >
> > I have some stored procedures which I would like changed from "User" to
> > "System". Does anyone know the fast way to do this?
> >
> > Thanks,
> >
> > Forch
> >
> >
>|||Those are the result of someone using the Diagram tool in EM. They're
generated
as system procs. I've never seem them listed as user procs. Personally,
I wouldn't
touch them.
"Forch" <forch@.somethere.com> wrote in message
news:em4kNJVAEHA.3220@.TK2MSFTNGP10.phx.gbl...
> Because one database has all of these stored procedure that start
with"dt_"
> and are shown as "system", while the exact duplicate database has the same
> "dt_" stored procedures and they are "user" stored procedures.
> Cheers,
> Forch
>
> "Armando" <blba2k@.yahoo.com> wrote in message
> news:ObB6PwUAEHA.448@.TK2MSFTNGP11.phx.gbl...
> > I'm curious... why do you need to do this?
> >
> > "Forch" <forch@.somethere.com> wrote in message
> > news:u2URsqUAEHA.3400@.tk2msftngp13.phx.gbl...
> > > Hi guys...
> > >
> > > I have some stored procedures which I would like changed from "User"
to
> > > "System". Does anyone know the fast way to do this?
> > >
> > > Thanks,
> > >
> > > Forch
> > >
> > >
> >
> >
>