Friday, March 30, 2012
How to simplify/optimize this query?
Could the following query be simplified/optimized? The database has a table
that maps users to locations, locations to chapters, and sections to
chapters. I need to issue a query that would return a list of sections that
can be assigned to a user (excluding the ones that have already been
assigned) .
@.UserId int
[...]
SELECT SectionID, [Name],
FROM Section
WHERE SectionID NOT IN (SELECT SectionID FROM UserSection WHERE UserID = @.UserID) AND
SectionID IN (SELECT DISTINCT SectionID FROM ChapterSection
WHERE ChapterID IN
(SELECT DISTINCT ChapterID FROM ChapterLocation
WHERE LocationID IN
(SELECT LocationID FROM UserLocation WHERE UserID = @.UserID)
)
);
I realize that this might not be as clear as it should be but I'd appreciate
_any_ suggestions.
Thanks,
Dan> Could the following query be simplified/optimized?
I think the query below is equivalent. I think indexes on the columns in
the WHERE/JOIN clauses may help performance(e.g. a composite index on
UserSection UserID, SectionID).
SELECT SectionID, [Name]
FROM dbo.Section s
WHERE
NOT EXISTS(
SELECT * FROM dbo.UserSection us
WHERE
us.SectionID = s.SectionID
AND UserID = @.UserID
) AND
EXISTS(
SELECT * FROM dbo.ChapterSection cs
JOIN dbo.ChapterLocation cl ON
cl.ChapterID = cs.ChapterID
JOIN dbo.UserLocation ul ON
ul.LocationID = cl.LocationID
AND UserID = @.UserID)
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"dan" <dan@.company.com> wrote in message
news:uVUBR7mqIHA.3804@.TK2MSFTNGP02.phx.gbl...
> Hi,
> Could the following query be simplified/optimized? The database has a
> table that maps users to locations, locations to chapters, and sections to
> chapters. I need to issue a query that would return a list of sections
> that can be assigned to a user (excluding the ones that have already been
> assigned) .
> @.UserId int
> [...]
> SELECT SectionID, [Name],
> FROM Section
> WHERE SectionID NOT IN (SELECT SectionID FROM UserSection WHERE UserID => @.UserID) AND
> SectionID IN (SELECT DISTINCT SectionID FROM ChapterSection
> WHERE ChapterID IN
> (SELECT DISTINCT ChapterID FROM ChapterLocation
> WHERE LocationID IN
> (SELECT LocationID FROM UserLocation WHERE UserID = @.UserID)
> )
> );
> I realize that this might not be as clear as it should be but I'd
> appreciate _any_ suggestions.
> Thanks,
> Dan
>|||Thanks for the reply. The query looks clean but there seems to be a problem
with EXISTS() in the WHERE clause. Some of the sections included in the
result set are not assigned to the user's location(s) (implicitly through
chapters). I.e. the query selects chapters that are not assigned to user's
locations in addition to the chapters that are assigned.
Any suggestions?
Thanks,
Dan
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:A400C6C3-53B6-4A01-B0DD-182ACF421236@.microsoft.com...
>> Could the following query be simplified/optimized?
> I think the query below is equivalent. I think indexes on the columns in
> the WHERE/JOIN clauses may help performance(e.g. a composite index on
> UserSection UserID, SectionID).
> SELECT SectionID, [Name]
> FROM dbo.Section s
> WHERE
> NOT EXISTS(
> SELECT * FROM dbo.UserSection us
> WHERE
> us.SectionID = s.SectionID
> AND UserID = @.UserID
> ) AND
> EXISTS(
> SELECT * FROM dbo.ChapterSection cs
> JOIN dbo.ChapterLocation cl ON
> cl.ChapterID = cs.ChapterID
> JOIN dbo.UserLocation ul ON
> ul.LocationID = cl.LocationID
> AND UserID = @.UserID)
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> http://weblogs.sqlteam.com/dang/
> "dan" <dan@.company.com> wrote in message
> news:uVUBR7mqIHA.3804@.TK2MSFTNGP02.phx.gbl...
>> Hi,
>> Could the following query be simplified/optimized? The database has a
>> table that maps users to locations, locations to chapters, and sections
>> to chapters. I need to issue a query that would return a list of sections
>> that can be assigned to a user (excluding the ones that have already been
>> assigned) .
>> @.UserId int
>> [...]
>> SELECT SectionID, [Name],
>> FROM Section
>> WHERE SectionID NOT IN (SELECT SectionID FROM UserSection WHERE UserID =>> @.UserID) AND
>> SectionID IN (SELECT DISTINCT SectionID FROM ChapterSection
>> WHERE ChapterID IN
>> (SELECT DISTINCT ChapterID FROM ChapterLocation
>> WHERE LocationID IN
>> (SELECT LocationID FROM UserLocation WHERE UserID = @.UserID)
>> )
>> );
>> I realize that this might not be as clear as it should be but I'd
>> appreciate _any_ suggestions.
>> Thanks,
>> Dan
>>
>|||> Thanks for the reply. The query looks clean but there seems to be a
> problem
> with EXISTS() in the WHERE clause. Some of the sections included in the
> result set are not assigned to the user's location(s) (implicitly through
> chapters). I.e. the query selects chapters that are not assigned to
> user's locations in addition to the chapters that are assigned.
> Any suggestions?
I missed the join from ChapterSection.SectionID back to Section.SectionID.
See the corrected query below. If this still doesn't work for you, please
post the table DDL and sample data so that I can test the solution.
SELECT SectionID, [Name]
FROM dbo.Section s
WHERE
NOT EXISTS(
SELECT * FROM dbo.UserSection us
WHERE
us.SectionID = s.SectionID
AND UserID = @.UserID
)
AND EXISTS(
SELECT * FROM dbo.ChapterSection cs
JOIN dbo.ChapterLocation cl ON
cl.ChapterID = cs.ChapterID
JOIN dbo.UserLocation ul ON
ul.LocationID = cl.LocationID
AND UserID = @.UserID
AND cs.SectionID = s.SectionID
)
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"dan" <dan@.company.com> wrote in message
news:eB2qg%23sqIHA.2492@.TK2MSFTNGP06.phx.gbl...
> Thanks for the reply. The query looks clean but there seems to be a
> problem with EXISTS() in the WHERE clause. Some of the sections included
> in the result set are not assigned to the user's location(s) (implicitly
> through chapters). I.e. the query selects chapters that are not assigned
> to user's locations in addition to the chapters that are assigned.
> Any suggestions?
> Thanks,
> Dan
> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
> news:A400C6C3-53B6-4A01-B0DD-182ACF421236@.microsoft.com...
>> Could the following query be simplified/optimized?
>> I think the query below is equivalent. I think indexes on the columns in
>> the WHERE/JOIN clauses may help performance(e.g. a composite index on
>> UserSection UserID, SectionID).
>> SELECT SectionID, [Name]
>> FROM dbo.Section s
>> WHERE
>> NOT EXISTS(
>> SELECT * FROM dbo.UserSection us
>> WHERE
>> us.SectionID = s.SectionID
>> AND UserID = @.UserID
>> ) AND
>> EXISTS(
>> SELECT * FROM dbo.ChapterSection cs
>> JOIN dbo.ChapterLocation cl ON
>> cl.ChapterID = cs.ChapterID
>> JOIN dbo.UserLocation ul ON
>> ul.LocationID = cl.LocationID
>> AND UserID = @.UserID)
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> http://weblogs.sqlteam.com/dang/
>> "dan" <dan@.company.com> wrote in message
>> news:uVUBR7mqIHA.3804@.TK2MSFTNGP02.phx.gbl...
>> Hi,
>> Could the following query be simplified/optimized? The database has a
>> table that maps users to locations, locations to chapters, and sections
>> to chapters. I need to issue a query that would return a list of
>> sections that can be assigned to a user (excluding the ones that have
>> already been assigned) .
>> @.UserId int
>> [...]
>> SELECT SectionID, [Name],
>> FROM Section
>> WHERE SectionID NOT IN (SELECT SectionID FROM UserSection WHERE UserID =>> @.UserID) AND
>> SectionID IN (SELECT DISTINCT SectionID FROM ChapterSection
>> WHERE ChapterID IN
>> (SELECT DISTINCT ChapterID FROM ChapterLocation
>> WHERE LocationID IN
>> (SELECT LocationID FROM UserLocation WHERE UserID = @.UserID)
>> )
>> );
>> I realize that this might not be as clear as it should be but I'd
>> appreciate _any_ suggestions.
>> Thanks,
>> Dan
>>
>|||Thanks. It works now.
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:5F09A613-CEF3-45CA-B2EA-6A3D39CB69D5@.microsoft.com...
>> Thanks for the reply. The query looks clean but there seems to be a
>> problem
>> with EXISTS() in the WHERE clause. Some of the sections included in the
>> result set are not assigned to the user's location(s) (implicitly through
>> chapters). I.e. the query selects chapters that are not assigned to
>> user's locations in addition to the chapters that are assigned.
>> Any suggestions?
> I missed the join from ChapterSection.SectionID back to Section.SectionID.
> See the corrected query below. If this still doesn't work for you, please
> post the table DDL and sample data so that I can test the solution.
> SELECT SectionID, [Name]
> FROM dbo.Section s
> WHERE
> NOT EXISTS(
> SELECT * FROM dbo.UserSection us
> WHERE
> us.SectionID = s.SectionID
> AND UserID = @.UserID
> )
> AND EXISTS(
> SELECT * FROM dbo.ChapterSection cs
> JOIN dbo.ChapterLocation cl ON
> cl.ChapterID = cs.ChapterID
> JOIN dbo.UserLocation ul ON
> ul.LocationID = cl.LocationID
> AND UserID = @.UserID
> AND cs.SectionID = s.SectionID
> )
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> http://weblogs.sqlteam.com/dang/
> "dan" <dan@.company.com> wrote in message
> news:eB2qg%23sqIHA.2492@.TK2MSFTNGP06.phx.gbl...
>> Thanks for the reply. The query looks clean but there seems to be a
>> problem with EXISTS() in the WHERE clause. Some of the sections included
>> in the result set are not assigned to the user's location(s) (implicitly
>> through chapters). I.e. the query selects chapters that are not assigned
>> to user's locations in addition to the chapters that are assigned.
>> Any suggestions?
>> Thanks,
>> Dan
>> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
>> news:A400C6C3-53B6-4A01-B0DD-182ACF421236@.microsoft.com...
>> Could the following query be simplified/optimized?
>> I think the query below is equivalent. I think indexes on the columns
>> in the WHERE/JOIN clauses may help performance(e.g. a composite index on
>> UserSection UserID, SectionID).
>> SELECT SectionID, [Name]
>> FROM dbo.Section s
>> WHERE
>> NOT EXISTS(
>> SELECT * FROM dbo.UserSection us
>> WHERE
>> us.SectionID = s.SectionID
>> AND UserID = @.UserID
>> ) AND
>> EXISTS(
>> SELECT * FROM dbo.ChapterSection cs
>> JOIN dbo.ChapterLocation cl ON
>> cl.ChapterID = cs.ChapterID
>> JOIN dbo.UserLocation ul ON
>> ul.LocationID = cl.LocationID
>> AND UserID = @.UserID)
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> http://weblogs.sqlteam.com/dang/
>> "dan" <dan@.company.com> wrote in message
>> news:uVUBR7mqIHA.3804@.TK2MSFTNGP02.phx.gbl...
>> Hi,
>> Could the following query be simplified/optimized? The database has a
>> table that maps users to locations, locations to chapters, and sections
>> to chapters. I need to issue a query that would return a list of
>> sections that can be assigned to a user (excluding the ones that have
>> already been assigned) .
>> @.UserId int
>> [...]
>> SELECT SectionID, [Name],
>> FROM Section
>> WHERE SectionID NOT IN (SELECT SectionID FROM UserSection WHERE UserID
>> = @.UserID) AND
>> SectionID IN (SELECT DISTINCT SectionID FROM ChapterSection
>> WHERE ChapterID IN
>> (SELECT DISTINCT ChapterID FROM ChapterLocation
>> WHERE LocationID IN
>> (SELECT LocationID FROM UserLocation WHERE UserID =>> @.UserID)
>> )
>> );
>> I realize that this might not be as clear as it should be but I'd
>> appreciate _any_ suggestions.
>> Thanks,
>> Dan
>>
>>
>
How to simplify this slow Stored Procedure
Is there anyway to write the following stored procedure without the loop so that it goes much faster? :confused:
-----------------------
use MJ_ReportBase
go
if exists(select 1 from sysobjects where type='P' and name='sp_Periode')
begin
drop procedure sp_Periode
end
go
create procedure sp_Periode
@.start int
, @.stop int
as
declare @.x int
set @.x = 0
set @.x=@.start
delete from tbl_periode
while (@.x>=@.stop)
begin
-- --
-- --
-- Create table tbl_inout
if exists(select 1 from sysobjects where type='U' and name='tbl_inout')
begin
drop table tbl_inout
end
select datetimestamp,accname,badgeid,personname,inoutreg into tbl_inout from WinXS..x18 where convert(varchar,datetimestamp,120)+' '+ltrim(str(id))+' '+ltrim(str(badgeid)) in
(select convert(varchar,max(datetimestamp),120)+' '+ltrim(str(max(id)))+' '+ltrim(str(badgeid)) as datetimestamp from WinXS..x18 where (accname='Kelder -1' or accname='Tnk Entree') and convert(varchar,datetimestamp,105)=convert(varchar ,getdate()-abs(@.x),105) group by badgeid)
and badgeid>0
order by personname
-- --
-- --
-- Create table tbl_result
if exists(select 1 from sysobjects where type='U' and name='tbl_result')
begin
drop table tbl_result
end
-- --
-- --
select
convert(varchar,datetimestamp,105) 'DATUM'
, badgeid 'PAS'
, initials 'VOORNAAM'
, personname 'NAAM'
, convert(varchar,min(datetimestamp),108) 'MIN'
, convert(varchar,max(datetimestamp),108) 'MAX'
into
tbl_result
from
WinXS..x18
where
convert(varchar,datetimestamp,105)=convert(varchar ,getdate()-abs(@.x),105)
and
accname in ('Kelder -1','Tnk Entree')
and badgeid>0
group by
convert(varchar,WinXS..x18.datetimestamp,105)
, badgeid
, initials
, personname
order by
initials
, personname asc
, convert(varchar,datetimestamp,105) asc
-- --
-- --
-- Rapportage tabel
insert into
tbl_periode
select
tbl_result.datum as DATUM
, ltrim(ltrim(rtrim(tbl_result.naam))+' '+ltrim(rtrim(isnull(tbl_result.voornaam,' ')))) as NAAM
, tbl_result.min as MIN
, tbl_result.max as MAX
, case tbl_inout.inoutreg when 1 then 'in' when 2 then 'out' else 'err' end as [IN/OUT]
, substring('00000',1,5-len(tbl_result.pas))+ltrim(str(tbl_result.pas)) as PAS
from
tbl_inout,tbl_result
where
tbl_result.datum+' '+tbl_result.max+' '+ltrim(str(tbl_result.pas))
= convert(varchar,tbl_inout.datetimestamp,105)+' '+convert(varchar,tbl_inout.datetimestamp,108)+' '+ltrim(str(badgeid))
order by
tbl_result.naam asc
-- --
-- --
--
set @.x=@.x-1
end
go
print 'Klaar!'
-----------------------
What it does is determining the minimum entry time and the maximum exiting time per day of people going true the main entrance of a building.
Many thanks in advance.
:)First...collapse the queries in to 1.
Second, what's the first select for?
Third
Loose the loop and do
WHERE datetimestamp > GetDate()-@.Start
AND datetimestamp < = GetDate()-@.Stop|||I don't even want to try to figure out your code. Don't use permanent tables for temporary storage (your tbl_inout table). That will get you into trouble in a multi-user environment.
Post the relevent DDL for your tables any somebody here can probably show you a more efficient set-based algorithm.|||Hi to all,
I have found the solution after a long time puzzeling. :)
Please check the sql below:
-----------------------
select
tbl_INOUT.*
, CASE B.inoutreg WHEN 1 THEN 'IN' WHEN 2 THEN 'UIT' ELSE 'Fout' END 'STATUS'
from
(
select
convert(char(10),datetimestamp,120) 'DATUM'
, badgeid 'PAS'
, initials 'VOORNAAM'
, personname 'NAAM'
, convert(varchar,min(datetimestamp),108) 'MIN'
, convert(varchar,max(datetimestamp),108) 'MAX'
from
WinXS..x18
where
(convert(varchar(10),datetimestamp,120)>=convert(varchar(10),'2005-01-01',120)
and
convert(varchar(10),datetimestamp,120)<=convert(varchar(10),'2005-02-28',120))
and
accname in ('Kelder -1','Tnk Entree')
and
badgeid>0
group by
convert(char(10),datetimestamp,120)
, badgeid
, initials
, personname
) tbl_INOUT, WinXS..x18 B
where
tbl_INOUT.pas=B.badgeid
and
convert(datetime,tbl_INOUT.datum+' '+tbl_INOUT.max,120)=B.datetimestamp
and
badgeid=81
order by
tbl_INOUT.naam asc
, tbl_INOUT.datum DESC
Greetz,
DePrins
:D
Monday, March 26, 2012
how to setup the permission of share fold in log shipping ?
I got the following error:
'Unable to copy the initialization file to the secondary server '%s' '
I know this is permission question about the share fold to log file.
I want to know the following thing:
one is how to setup permisson about about the share fold to log file?
two is whether log shpping primary and the secondary db must be run
in domin mode or not?
thanks in advance!
1. if your logshipping jobs are owned by 'sa', the acct for sqlserver
service needs to have access to the shared.
2. no, they do not have to be running in a same domain. the key here is to
ensure each server can access the shared.
-oj
<lovexueer@.gmail.com> wrote in message
news:1143611950.475014.180370@.i39g2000cwa.googlegr oups.com...
> when I set up log shipping in SQL SERVER 2000
> I got the following error:
> 'Unable to copy the initialization file to the secondary server '%s' '
> I know this is permission question about the share fold to log file.
> I want to know the following thing:
> one is how to setup permisson about about the share fold to log file?
> two is whether log shpping primary and the secondary db must be run
> in domin mode or not?
>
> thanks in advance!
>
how to setup the permission of share fold in log shipping ?
I got the following error:
'Unable to copy the initialization file to the secondary server '%s' '
I know this is permission question about the share fold to log file.
I want to know the following thing:
one is how to setup permisson about about the share fold to log file?
two is whether log shpping primary and the secondary db must be run
in domin mode or not?
thanks in advance!1. if your logshipping jobs are owned by 'sa', the acct for sqlserver
service needs to have access to the shared.
2. no, they do not have to be running in a same domain. the key here is to
ensure each server can access the shared.
-oj
<lovexueer@.gmail.com> wrote in message
news:1143611950.475014.180370@.i39g2000cwa.googlegroups.com...
> when I set up log shipping in SQL SERVER 2000
> I got the following error:
> 'Unable to copy the initialization file to the secondary server '%s' '
> I know this is permission question about the share fold to log file.
> I want to know the following thing:
> one is how to setup permisson about about the share fold to log file?
> two is whether log shpping primary and the secondary db must be run
> in domin mode or not?
>
> thanks in advance!
>
how to setup the permission of share fold in log shipping ?
I got the following error:
'Unable to copy the initialization file to the secondary server '%s' '
I know this is permission question about the share fold to log file.
I want to know the following thing:
one is how to setup permisson about about the share fold to log file?
two is whether log shpping primary and the secondary db must be run
in domin mode or not?
thanks in advance!1. if your logshipping jobs are owned by 'sa', the acct for sqlserver
service needs to have access to the shared.
2. no, they do not have to be running in a same domain. the key here is to
ensure each server can access the shared.
--
-oj
<lovexueer@.gmail.com> wrote in message
news:1143611950.475014.180370@.i39g2000cwa.googlegroups.com...
> when I set up log shipping in SQL SERVER 2000
> I got the following error:
> 'Unable to copy the initialization file to the secondary server '%s' '
> I know this is permission question about the share fold to log file.
> I want to know the following thing:
> one is how to setup permisson about about the share fold to log file?
> two is whether log shpping primary and the secondary db must be run
> in domin mode or not?
>
> thanks in advance!
>|||sorry,I don't understand what you said to the first quesiton?
can you tell furthur detailed information about how to setup the
permisson of shared fold ?sql
Monday, March 19, 2012
How to set up a username and password for MSDE
I have installed MSDE using the following parameter:
commandline> setup SAPWD="MySAPwd"
now all was set up... when i opened the osql utility..i wasnt able to login... it kept asking me the login name ans password...
i entered my windows login name which is 'home' and entered 'kham00s' as the password... it didnt work... then i entered my windows login name again which is 'home' and entered 'OTHERPASSWORD' as the password which is my system password...but did not work either...
then i logged in using :
commandline> osql -E
It successfully logged in... and i was able to create databases and tables...
can someone tell me how to set a username and password for MSDE please... so that i can connect to MSDE using WebMatrix...
i m coming from a PHP/MySQL background so i know SQL and stuff... but dont know how to handle and configure MSSQL...
waiting for the response..
thanks in advance...
Bye.
Kamran.The SAPWD option sets the sa users password, and so you need to use a username of sa and the password you supplied.
I edited your message so that your passwaords are not visible...|||thanks douglas! :)
But can you plz tell me what is my sa username? i read the term 'sa' a lot in the msdn library but couldnt figure out what it means... it wud be gr8 if i get to know what is 'sa'...
btw thanks for editing...but the passwords i entered were not the real ones. ;)
looking forward to replies.. thanks...|||The sa password is 'sa' (without the quotes).|||thanks again...
but that isnt working either...
after installation.. i do this:
commandline> osql -U sa -P "mypwd"
also tried this:
commandline> osql -U sa -P mypwd
and this:
commandline> osql -U sa
enter password: (keyboard hits)
but doesnt connect either... tells me that 'sa' is an unknown user... etc...
plz help me... i can connect using the -E parameter...but i need to connect to MSDE using ASP.net Web Matrix... so plz help... many thanks...
regards,
Kamran.|||Here is the procedure for adding a user to a database (from the "Microsoft ASP.NET Programming C# .NET" book):
When you installed your .NET IDE, it should have set up an ASPNET Windows user account. ASP.NET is configured by default to use the unprivileged ASPNET account to run ASP.NET worker processes.
1)
comline: osql -E
2)
grant login access to the ASPNET account. <domain> is your local machine name.
1> sp_grantlogin '<domain>\ASPNET'
2> go
3)
call the sp_defaultdb system stored procedure to change the default database to the database you want ASPNET to use.
1> sp_defaultdb '<domain>\ASPNET', '<yourdatabasename>'
2> go
4)
add the ASPNET account to the db_datareader role.
1> sp_adduser '<domain>\ASPNET', 'ASPNET', 'db_datareader'
2> go
5)
to add ASPNET to the db_datawriter role, do:
1> sp_addrolemember 'db_datawriter', 'ASPNET'
2> go|||thanks everyone...
all is working fine now... thanks to douglas and dran001...
i m able to ger web matrix connect to the database...
btw i m unable to connect through web data administrator... thankx anyways...
i hav no probs 'inserting' using OSQL...
regards,
Kamran.
How to set this parameter AlwaysUseDefaultCodePath="TRUE"
I am trying to migrate date from Oracle 10g to SQL serve 2005 during the data transformation I get the following error
Messages
Warning 0x80202066: Source - SERVICE [1]: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.
(SQL Server Import and Export Wizard)
I searched internet and solution seems to be setting AlwaysUseDefaultCodePath="TRUE"
But where do you do this ?
I found this too: It's on the Properties tab of the OLE DB Source in Custom Properties section.
But still do not know where to go to set this parameter
Please help
The AlwaysUseDefaultCodePath property may be available in the Advanced Editor for the OLE DB Source. This editor has a Component Properties tab, and Input and Output Properties tab.
To open the Advanced Editor, right-click the OLE DB Source component in the package, and then click Advanced Editor.
|||For thi styoe of property I normally find it faster and easier to just use the Properties window in the designer, rather than opening the Editor. Select the component, and then hit F4 to bring the properties window into focus if it is not already.|||Thanks, Thats what I was looking for, it resolve my issueHow to set this parameter AlwaysUseDefaultCodePath="TRUE"
I am trying to migrate date from Oracle 10g to SQL serve 2005 during the data transformation I get the following error
Messages
Warning 0x80202066: Source - SERVICE [1]: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.
(SQL Server Import and Export Wizard)
I searched internet and solution seems to be setting AlwaysUseDefaultCodePath="TRUE"
But where do you do this ?
I found this too: It's on the Properties tab of the OLE DB Source in Custom Properties section.
But still do not know where to go to set this parameter
Please help
The AlwaysUseDefaultCodePath property may be available in the Advanced Editor for the OLE DB Source. This editor has a Component Properties tab, and Input and Output Properties tab.
To open the Advanced Editor, right-click the OLE DB Source component in the package, and then click Advanced Editor.
|||For thi styoe of property I normally find it faster and easier to just use the Properties window in the designer, rather than opening the Editor. Select the component, and then hit F4 to bring the properties window into focus if it is not already.|||Thanks, Thats what I was looking for, it resolve my issueHow to set this parameter AlwaysUseDefaultCodePath="TRUE"
I am trying to migrate date from Oracle 10g to SQL serve 2005 during the data transformation I get the following error
Messages
Warning 0x80202066: Source - SERVICE [1]: Cannot retrieve the column code page info from the OLE DB provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used.
(SQL Server Import and Export Wizard)
I searched internet and solution seems to be setting AlwaysUseDefaultCodePath="TRUE"
But where do you do this ?
I found this too: It's on the Properties tab of the OLE DB Source in Custom Properties section.
But still do not know where to go to set this parameter
Please help
The AlwaysUseDefaultCodePath property may be available in the Advanced Editor for the OLE DB Source. This editor has a Component Properties tab, and Input and Output Properties tab.
To open the Advanced Editor, right-click the OLE DB Source component in the package, and then click Advanced Editor.
|||For thi styoe of property I normally find it faster and easier to just use the Properties window in the designer, rather than opening the Editor. Select the component, and then hit F4 to bring the properties window into focus if it is not already.|||Thanks, Thats what I was looking for, it resolve my issueMonday, March 12, 2012
How to set the following report Parameters?
Hi,
I have a report and the parameters Passed to the report are Cusip and PeriodId through a stored Procedure.
i want to populate the cusip Parameters using a dataset thats got by a sproc called usp_getCusips.
and the PerioId using a dataset thats been got by another sproc called usp_Getperiods...
So in my report i have added 3 datasets one for the main report, one to get the values of the PeriodId and other to get the value of the cusip.
So in my Report parameters for the Parameter Cusip and i have checked the Available value option and selected its corresponding Dataset and value .
and i have also done the same thing for the PeriodId.. But when i run my sproc i am getting this Error.
[rsInvalidReportParameterDependency] The report parameter ‘Cusip’ has a DefaultValue or a ValidValue that depends on the report parameter “Cusip”. Forward dependencies are not valid.
[rsInvalidReportParameterDependency] The report parameter ‘PeriodId’ has a DefaultValue or a ValidValue that depends on the report parameter “PeriodId”. Forward dependencies are not valid.
Any Help will be appreciated.
Regards,
Karen
I'm not sure how to directly answer your question, but it sounds like you have created a circular reference.
See the following thread.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=184243&SiteID=1
|||
Greg,
Thanks for the help, i got it to work.
Regards
Karen
|||Glad I could help.
Friday, March 9, 2012
How to set sheetname on an Excel destination component ?
Hello, I am trying to create a simple package programmatically. I am following the examples in the BOL, and from some advice here. I am getting stuck at creating an Excel Destination and setting its sheetname. Everything works fine, including setting the output Excel filename. I get a runtime exception when I try to set the sheetname via SetComponentProperty. Is there another way, or am I doing something wrong? Thanks for any info you may have.
' Create and configure an OLE DB destination.
Dim conDest As ConnectionManager = package.Connections.Add("Excel")
conDest.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Dts.Variables("User::gsExcelFile").Value.ToString & ";Extended Properties=""Excel 8.0;HDR=YES"""
conDest.Name = "Excel File"
conDest.Description = "Excel File"
Dim destination As IDTSComponentMetaData90 = dataFlowTask.ComponentMetaDataCollection.New
destination.ComponentClassID = "DTSAdapter.ExcelDestination"
' Create the design-time instance of the destination.
Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate
' The ProvideComponentProperties method creates a default input.
destDesignTime.ProvideComponentProperties()
destination.RuntimeConnectionCollection(0).ConnectionManager = DtsConvert.ToConnectionManager90(conDest)
destDesignTime.SetComponentProperty("AccessMode", 0)
'runtime Exception here
destDesignTime.SetComponentProperty("OpenRowSet", "functions")
Guess time!
If you post the error details, it normally helps. I'll guess at error HResult 0xC0204006, some notes - http://wiki.sqlis.com/default.aspx/SQLISWiki/0xC0204006.html
Properties are case sensitive, and it is called OpenRowset not OpenRowSet.
How did i do?
|||Yep, the case sensitivity was it. Thanks!How to set sheetname on an Excel destination component ?
Hello, I am trying to create a simple package programmatically. I am following the examples in the BOL, and from some advice here. I am getting stuck at creating an Excel Destination and setting its sheetname. Everything works fine, including setting the output Excel filename. I get a runtime exception when I try to set the sheetname via SetComponentProperty. Is there another way, or am I doing something wrong? Thanks for any info you may have.
' Create and configure an OLE DB destination.
Dim conDest As ConnectionManager = package.Connections.Add("Excel")
conDest.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Dts.Variables("User::gsExcelFile").Value.ToString & ";Extended Properties=""Excel 8.0;HDR=YES"""
conDest.Name = "Excel File"
conDest.Description = "Excel File"
Dim destination As IDTSComponentMetaData90 = dataFlowTask.ComponentMetaDataCollection.New
destination.ComponentClassID = "DTSAdapter.ExcelDestination"
' Create the design-time instance of the destination.
Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate
' The ProvideComponentProperties method creates a default input.
destDesignTime.ProvideComponentProperties()
destination.RuntimeConnectionCollection(0).ConnectionManager = DtsConvert.ToConnectionManager90(conDest)
destDesignTime.SetComponentProperty("AccessMode", 0)
'runtime Exception here
destDesignTime.SetComponentProperty("OpenRowSet", "functions")
Guess time!
If you post the error details, it normally helps. I'll guess at error HResult 0xC0204006, some notes - http://wiki.sqlis.com/default.aspx/SQLISWiki/0xC0204006.html
Properties are case sensitive, and it is called OpenRowset not OpenRowSet.
How did i do?
|||Yep, the case sensitivity was it. Thanks!Wednesday, March 7, 2012
how to set Formula Grouping in Crystal report 9
01 - 02
02-03
04-05
..
.
.
.
.
.
21-22
22-23
23-24
24-01
and as per this group i want to give different running total.On create new group form select "Use formula as group" option and write down your's desire formula.
you can write formula as
if{@.Cond}='1' then
'01 - 02'
else if {@.Cond}='2' then
'02 - 03'
...
...
and so on|||thanks Anand
but i want to create a group with 01-02 , 02-03, 03-04 and so on up to 23-24, 24-01. and there not a single field in database which can represent this type of group
so plz let me know as eairly as possible|||?
Do you mean you want to group like this:
01 - 02 // or may be 00 - 01 ?
03 - 04
05 - 06
.
.
24 - 00 ?
I don't really understand what do you mean by '01 - 02' and '02 - 03' ?
The hour 02 can be included just into one group.
OK, if {your_table.date_time_field} you want to group by, returns date_time or time, create a formula @.Hour:
hour({your_table.date_time_field})
then you will be able to create another formula @.Groupping_by_Hour:
if {@.Hour} in [0,1] then '0 - 1' else
if {@.Hour} in [2,3] then '2 - 3' else
.
.
if {@.Hour} in [20,21] then '20 - 21' else '22_23'|||i want report as follows
time! No of person came for interview
01 am: 02 am 1
02am : 03am 1
03am : 04am 2
04am : 05am 1
.
.
.
21 pm : 22 pm 1
22 pm : 23 pm 1
23 pm : 24 pm 1
24 pm : 01 am 1
i don't have any field which i an get time. but i want a group as per time. and i have a field of noof person came for interviw and their time|||You had to post a such info in your first post. When you say you need to group the records by hour, it sounds (at least for me) that you have some {table.date_time} field, otherwise how you can get an hour to group your records on, if you don't have a such field.
So, from your last post I understand that you have 2 fields:
the 1st one is time the person came for his/her interview at, again, it sounds like it's a date_time field, but you didn't say anything about your field formats;
the 2nd one is 'their time';
Which time? Is that a numeric field which containes a number of hours/minutes the person had been interviewing for or the time when he/she left (date_time field)... or :) their time they had an appointment at?
Can you post an example of these fields?|||sorry friend, for providing inproper information, i have a form in which i accept name of person, addres and other details of a person who came for interview and his timing of arrival. and thus the information is stored in the database with timing of arrival as datetime. now i want a report which shows count of person arrived for interview between
01:00 to 02:00 am
02:00 to 03:00 am
03:00 to 04:00 am
04:00 to 05:00 am
.
.
.
.
.
.
..
.
.
.21:00 to 22:00 pm
22:00 to 23:00 pm
23:00 to 24:00 pm
24:00 to 01:00 am
if the information is still in proper plz let me know|||:) it's OK.
So why did you say you 'don't have any field which u can get time' if you have info 'stored in the database with timing of arrival as datetime' ?
Use that field, this is the one you need.
I probably understood you wrong about how you want to group your records (I really need my vacation :)).
I guess you actually want to group by hour
01:00 to 02:00 am // this is time from 1:00:00 am to 1:59:59 am
02:00 to 03:00 am // that is time from 2:00:00 am to 2:59:59 am
.
.
but in your GF you would like to have a note like these
01-02
02-03
.
.
Right?
You can group your records on {your_table.timing_of_arrival} field by hour, which you said was datetime field;
for 'The section will be printed' select 'for each hour'.
Count how many people came for interview each hour. You might have a person ID field or something so, right click on it -> insert -> summary;
for calculate this summary select 'Count'
for summary location select group based on that field.
Suppress GH and Details sections
then create a formula @.Groupping
local numbervar HH:=hour({your_table.timing_of_arrival});
if HH=1 then '01 - 02' else
if HH=2 then '02 - 03' else
if HH=3 then '03 - 04' else
.
.
.
if HH=22 then '22 - 23' else
if HH=23 then '23 - 24' else
if HH=0 then '24 - 01'
Place it in the Group Footer|||thanks,
but one small problem. i am getting group of hours only if the person came within that range of hours and if no one came for interview withing that hour then the group is not shown. eg
if 2 person came for interview between 11:00 - 12:00 then group is shown
and if no one came between 2:00 - 3:00 then group of 2:00-3:00 is not shown
and i want that all hours must be displayed.|||Ah, that old chestnut - used to be a common question but I haven't seen it for a while.
I believe the concensus was that you need a table containing all of the values that you want to display, and use this as the main table for the report with either
1) a left join to your table containing the times
or
2) running a subreport for each record in the main table, i.e. you'll run a subreport 24 times, once per hour period.
Friday, February 24, 2012
how to set collation to SQL_Latin1_General_CP1_CI_AS at install ?
All my USER DB have been created using the following collationL
SQL_Latin1_General_CP1_CI_AS
My "SQL instance 1" uses :
Latin1_General_CI_AS
Im in the process of setting up "SQL instance 2" and cannot find an option
to set the collation to SQL_Latin1_General_CP1_CI_AS
At install the "COLLATION DESIGNATOR and sort order" field shows
LATIN1_GENERAL.
The "SQL collations...." option below shows various options.
I cannot see an options to setup as "SQL_Latin1_General_CP1_CI_AS" or
"Latin1_General_CI_AS".
How can i use the setup wizard to select "SQL_Latin1_General_CP1_CI_AS"
Thanks for any help
Scott
(SQL 2005 standard - english)CP1 specifies code page 1252, for all other code pages the complete code
page number is specified.
CI specifies case-insensitive
AS specifies accent-sensitive.
Sort order ID SQL collation name
52 SQL_Latin1_General_Cp1_CI_AS
For more information about this topic, you can refer to the following link:
http://msdn2.microsoft.com/en-us/library/ms180175.aspx
Ekrem Önsoy
"Scott" <s@.yahoo.co.uk> wrote in message
news:O2pRP4%23CIHA.1212@.TK2MSFTNGP05.phx.gbl...
> help
> All my USER DB have been created using the following collationL
> SQL_Latin1_General_CP1_CI_AS
> My "SQL instance 1" uses :
> Latin1_General_CI_AS
> Im in the process of setting up "SQL instance 2" and cannot find an option
> to set the collation to SQL_Latin1_General_CP1_CI_AS
> At install the "COLLATION DESIGNATOR and sort order" field shows
> LATIN1_GENERAL.
> The "SQL collations...." option below shows various options.
> I cannot see an options to setup as "SQL_Latin1_General_CP1_CI_AS" or
> "Latin1_General_CI_AS".
> How can i use the setup wizard to select "SQL_Latin1_General_CP1_CI_AS"
> Thanks for any help
> Scott
> (SQL 2005 standard - english)
>
>|||thats helpful, many thanks
scott
Sunday, February 19, 2012
How to sequentially SORT numbers that also have a letter attached?
I'm hoping this will be straightforward for you guys to point me in the
right direction.
Friend of mine emailed me asking the following:
We have a table with a house plot number on it, which is varchar(5).
Example values are:
1
1a
1b
1c
2
2a
2b
2c
3
3a
3b
3c
11a
21c
When we sort these they come out as follows:
1
1a
1b
1c
11a
2
2a
2b
2c
21c
3
3a
3b
3c
Is there an easy way to get them to sort as per the first example? I.e.
1 first, then 1a, 1b, 1c followed by 2, 2a etc and not 11a?
I thought it'd be simple but not so! Would appreciate your advice on
the simplest way of achieving this please.Try:
declare @.t table
(
x varchar (5) primary key
, y as case when patindex ('%[a-z]', x) = 0 then ''
else right (x, len (x) - patindex ('%[a-z]', x) + 1) end
, z as case when patindex ('%[a-z]', x) = 0 then cast (x as int)
else cast (left (x, patindex ('%[a-z]', x) - 1) as int) end
)
insert @.t values ('1')
insert @.t values ('1a')
insert @.t values ('1b')
insert @.t values ('1c')
insert @.t values ('2')
insert @.t values ('2a')
insert @.t values ('2b')
insert @.t values ('2c')
insert @.t values ('3')
insert @.t values ('3a')
insert @.t values ('3b')
insert @.t values ('3c')
insert @.t values ('11a')
insert @.t values ('21c')
select x from @.t
order by z, y
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"ALI" <kismet110@.yahoo.co.uk> wrote in message
news:1150111751.001833.272460@.f14g2000cwb.googlegroups.com...
Hi
I'm hoping this will be straightforward for you guys to point me in the
right direction.
Friend of mine emailed me asking the following:
We have a table with a house plot number on it, which is varchar(5).
Example values are:
1
1a
1b
1c
2
2a
2b
2c
3
3a
3b
3c
11a
21c
When we sort these they come out as follows:
1
1a
1b
1c
11a
2
2a
2b
2c
21c
3
3a
3b
3c
Is there an easy way to get them to sort as per the first example? I.e.
1 first, then 1a, 1b, 1c followed by 2, 2a etc and not 11a?
I thought it'd be simple but not so! Would appreciate your advice on
the simplest way of achieving this please.|||Thanks for your help Tom, hopefully this will get them what they want,
I don't feel totally stupid now too for thinking it would be _really_
simple!
Tom Moreau wrote:
> Try:
> declare @.t table
> (
> x varchar (5) primary key
> , y as case when patindex ('%[a-z]', x) = 0 then ''
> else right (x, len (x) - patindex ('%[a-z]', x) + 1) end
> , z as case when patindex ('%[a-z]', x) = 0 then cast (x as int)
> else cast (left (x, patindex ('%[a-z]', x) - 1) as int) end
> )
> insert @.t values ('1')
> insert @.t values ('1a')
> insert @.t values ('1b')
> insert @.t values ('1c')
> insert @.t values ('2')
> insert @.t values ('2a')
> insert @.t values ('2b')
> insert @.t values ('2c')
> insert @.t values ('3')
> insert @.t values ('3a')
> insert @.t values ('3b')
> insert @.t values ('3c')
> insert @.t values ('11a')
> insert @.t values ('21c')
> select x from @.t
> order by z, y
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> .
> "ALI" <kismet110@.yahoo.co.uk> wrote in message
> news:1150111751.001833.272460@.f14g2000cwb.googlegroups.com...
> Hi
> I'm hoping this will be straightforward for you guys to point me in the
> right direction.
> Friend of mine emailed me asking the following:
> We have a table with a house plot number on it, which is varchar(5).
> Example values are:
> 1
> 1a
> 1b
> 1c
> 2
> 2a
> 2b
> 2c
> 3
> 3a
> 3b
> 3c
> 11a
> 21c
> When we sort these they come out as follows:
> 1
> 1a
> 1b
> 1c
> 11a
> 2
> 2a
> 2b
> 2c
> 21c
> 3
> 3a
> 3b
> 3c
> Is there an easy way to get them to sort as per the first example? I.e.
> 1 first, then 1a, 1b, 1c followed by 2, 2a etc and not 11a?
> I thought it'd be simple but not so! Would appreciate your advice on
> the simplest way of achieving this please.
how to send sql mail using condition statement
if do not have duplicate data, then the table will be dropped. While
if have duplicate data, the table will not be dropped but an email
notification will be sent. Why when there is no duplicate data, the
email still will be sent out?
if not exists(select catalog_code, count(catalog_code) from rd_awards
group
by catalog_code having
count(catalog_code) > 1)
begin
drop table [dbo].[Rewards_CatalogProducts_CS]
end
else
if exists(select catalog_code, count(catalog_code) from rd_awards
group
by catalog_code having
count(catalog_code) > 1)
use master
go
declare @.FROM NVARCHAR(4000),
@.FROM_NAME NVARCHAR(4000),
@.TO NVARCHAR(4000),
@.CC NVARCHAR(4000),
@.BCC NVARCHAR(4000),
@.priority NVARCHAR(10),
@.subject NVARCHAR(4000),
@.message NVARCHAR(4000),
@.type NVARCHAR(100),
@.attachments NVARCHAR(4000),
@.codepage INT,
@.rc INT
select @.FROM = N'sqlmail@.cyber-village.net',
@.FROM_NAME = N'ChangMian',
@.TO = N'tchangmian@.yahoo.com.sg',
@.CC = N'changmian@.cyber-village.net',
@.priority = N'High',
@.subject = N'Ei,can wor',
@.message = N'&
Hello SQL Server SMTP SQL
',
@.type = N'text/html',
@.attachments = N'',
@.codepage = 0
exec @.rc = master.dbo.xp_smtp_sendmail
@.FROM = @.FROM,
@.TO = @.TO,
@.CC = @.CC,
@.priority = @.priority,
@.subject = @.subject,
@.message = @.message,
@.type = @.type,
@.attachments = @.attachments,
@.codepage = @.codepage,
@.server = N'mail.cyber-village.net'
select RC = @.rc
goYour send mail script is in a different batch because of the 'GO' batch
terminator. Consider revising your script like the example below:
declare @.FROM NVARCHAR(4000),
@.FROM_NAME NVARCHAR(4000),
@.TO NVARCHAR(4000),
@.CC NVARCHAR(4000),
@.BCC NVARCHAR(4000),
@.priority NVARCHAR(10),
@.subject NVARCHAR(4000),
@.message NVARCHAR(4000),
@.type NVARCHAR(100),
@.attachments NVARCHAR(4000),
@.codepage INT,
@.rc INT
if not exists(select catalog_code, count(catalog_code) from rd_awards
group
by catalog_code having
count(catalog_code) > 1)
begin
drop table [dbo].[Rewards_CatalogProducts_CS]
end
else
begin
select @.FROM = N'sqlmail@.cyber-village.net',
@.FROM_NAME = N'ChangMian',
@.TO = N'tchangmian@.yahoo.com.sg',
@.CC = N'changmian@.cyber-village.net',
@.priority = N'High',
@.subject = N'Ei,can wor',
@.message = N'&
Hello SQL Server SMTP SQL
',
@.type = N'text/html',
@.attachments = N'',
@.codepage = 0
exec @.rc = master.dbo.xp_smtp_sendmail
@.FROM = @.FROM,
@.TO = @.TO,
@.CC = @.CC,
@.priority = @.priority,
@.subject = @.subject,
@.message = @.message,
@.type = @.type,
@.attachments = @.attachments,
@.codepage = @.codepage,
@.server = N'mail.cyber-village.net'
select RC = @.rc
end
go
--
Hope this helps.
Dan Guzman
SQL Server MVP
"tchangmian" <tchangmian@.yahoo.com.sg> wrote in message
news:6447ee25.0410042022.52f52ac5@.posting.google.com...
>I try to run the following code in DTS, but i not work. What i want is
> if do not have duplicate data, then the table will be dropped. While
> if have duplicate data, the table will not be dropped but an email
> notification will be sent. Why when there is no duplicate data, the
> email still will be sent out?
>
> if not exists(select catalog_code, count(catalog_code) from rd_awards
> group
> by catalog_code having
> count(catalog_code) > 1)
> begin
> drop table [dbo].[Rewards_CatalogProducts_CS]
> end
>
> else
> if exists(select catalog_code, count(catalog_code) from rd_awards
> group
> by catalog_code having
> count(catalog_code) > 1)
>
> use master
> go
> declare @.FROM NVARCHAR(4000),
> @.FROM_NAME NVARCHAR(4000),
> @.TO NVARCHAR(4000),
> @.CC NVARCHAR(4000),
> @.BCC NVARCHAR(4000),
> @.priority NVARCHAR(10),
> @.subject NVARCHAR(4000),
> @.message NVARCHAR(4000),
> @.type NVARCHAR(100),
> @.attachments NVARCHAR(4000),
> @.codepage INT,
> @.rc INT
> select @.FROM = N'sqlmail@.cyber-village.net',
> @.FROM_NAME = N'ChangMian',
> @.TO = N'tchangmian@.yahoo.com.sg',
> @.CC = N'changmian@.cyber-village.net',
> @.priority = N'High',
> @.subject = N'Ei,can wor',
> @.message = N'<HTML><H1>Hello SQL Server SMTP SQL
> Mail</H1></HTML>',
> @.type = N'text/html',
> @.attachments = N'',
> @.codepage = 0
> exec @.rc = master.dbo.xp_smtp_sendmail
> @.FROM = @.FROM,
> @.TO = @.TO,
> @.CC = @.CC,
> @.priority = @.priority,
> @.subject = @.subject,
> @.message = @.message,
> @.type = @.type,
> @.attachments = @.attachments,
> @.codepage = @.codepage,
> @.server = N'mail.cyber-village.net'
> select RC = @.rc
> go
how to send sql mail using condition statement
if do not have duplicate data, then the table will be dropped. While
if have duplicate data, the table will not be dropped but an email
notification will be sent. Why when there is no duplicate data, the
email still will be sent out?
if not exists(select catalog_code, count(catalog_code) from rd_awards
group
by catalog_code having
count(catalog_code) > 1)
begin
drop table [dbo].[Rewards_CatalogProducts_CS]
end
else
if exists(select catalog_code, count(catalog_code) from rd_awards
group
by catalog_code having
count(catalog_code) > 1)
use master
go
declare @.FROM NVARCHAR(4000),
@.FROM_NAME NVARCHAR(4000),
@.TO NVARCHAR(4000),
@.CC NVARCHAR(4000),
@.BCC NVARCHAR(4000),
@.priority NVARCHAR(10),
@.subject NVARCHAR(4000),
@.message NVARCHAR(4000),
@.type NVARCHAR(100),
@.attachments NVARCHAR(4000),
@.codepage INT,
@.rc INT
select @.FROM = N'sqlmail@.cyber-village.net',
@.FROM_NAME = N'ChangMian',
@.TO = N'tchangmian@.yahoo.com.sg',
@.CC = N'changmian@.cyber-village.net',
@.priority = N'High',
@.subject = N'Ei,can wor',
@.message = N'<HTML><H1>Hello SQL Server SMTP SQL
Mail</H1></HTML>',
@.type = N'text/html',
@.attachments = N'',
@.codepage = 0
exec @.rc = master.dbo.xp_smtp_sendmail
@.FROM = @.FROM,
@.TO = @.TO,
@.CC = @.CC,
@.priority = @.priority,
@.subject = @.subject,
@.message = @.message,
@.type = @.type,
@.attachments = @.attachments,
@.codepage = @.codepage,
@.server = N'mail.cyber-village.net'
select RC = @.rc
go
Your send mail script is in a different batch because of the 'GO' batch
terminator. Consider revising your script like the example below:
declare @.FROM NVARCHAR(4000),
@.FROM_NAME NVARCHAR(4000),
@.TO NVARCHAR(4000),
@.CC NVARCHAR(4000),
@.BCC NVARCHAR(4000),
@.priority NVARCHAR(10),
@.subject NVARCHAR(4000),
@.message NVARCHAR(4000),
@.type NVARCHAR(100),
@.attachments NVARCHAR(4000),
@.codepage INT,
@.rc INT
if not exists(select catalog_code, count(catalog_code) from rd_awards
group
by catalog_code having
count(catalog_code) > 1)
begin
drop table [dbo].[Rewards_CatalogProducts_CS]
end
else
begin
select @.FROM = N'sqlmail@.cyber-village.net',
@.FROM_NAME = N'ChangMian',
@.TO = N'tchangmian@.yahoo.com.sg',
@.CC = N'changmian@.cyber-village.net',
@.priority = N'High',
@.subject = N'Ei,can wor',
@.message = N'<HTML><H1>Hello SQL Server SMTP SQL
Mail</H1></HTML>',
@.type = N'text/html',
@.attachments = N'',
@.codepage = 0
exec @.rc = master.dbo.xp_smtp_sendmail
@.FROM = @.FROM,
@.TO = @.TO,
@.CC = @.CC,
@.priority = @.priority,
@.subject = @.subject,
@.message = @.message,
@.type = @.type,
@.attachments = @.attachments,
@.codepage = @.codepage,
@.server = N'mail.cyber-village.net'
select RC = @.rc
end
go
Hope this helps.
Dan Guzman
SQL Server MVP
"tchangmian" <tchangmian@.yahoo.com.sg> wrote in message
news:6447ee25.0410042022.52f52ac5@.posting.google.c om...
>I try to run the following code in DTS, but i not work. What i want is
> if do not have duplicate data, then the table will be dropped. While
> if have duplicate data, the table will not be dropped but an email
> notification will be sent. Why when there is no duplicate data, the
> email still will be sent out?
>
> if not exists(select catalog_code, count(catalog_code) from rd_awards
> group
> by catalog_code having
> count(catalog_code) > 1)
> begin
> drop table [dbo].[Rewards_CatalogProducts_CS]
> end
>
> else
> if exists(select catalog_code, count(catalog_code) from rd_awards
> group
> by catalog_code having
> count(catalog_code) > 1)
>
> use master
> go
> declare @.FROM NVARCHAR(4000),
> @.FROM_NAME NVARCHAR(4000),
> @.TO NVARCHAR(4000),
> @.CC NVARCHAR(4000),
> @.BCC NVARCHAR(4000),
> @.priority NVARCHAR(10),
> @.subject NVARCHAR(4000),
> @.message NVARCHAR(4000),
> @.type NVARCHAR(100),
> @.attachments NVARCHAR(4000),
> @.codepage INT,
> @.rc INT
> select @.FROM = N'sqlmail@.cyber-village.net',
> @.FROM_NAME = N'ChangMian',
> @.TO = N'tchangmian@.yahoo.com.sg',
> @.CC = N'changmian@.cyber-village.net',
> @.priority = N'High',
> @.subject = N'Ei,can wor',
> @.message = N'<HTML><H1>Hello SQL Server SMTP SQL
> Mail</H1></HTML>',
> @.type = N'text/html',
> @.attachments = N'',
> @.codepage = 0
> exec @.rc = master.dbo.xp_smtp_sendmail
> @.FROM = @.FROM,
> @.TO = @.TO,
> @.CC = @.CC,
> @.priority = @.priority,
> @.subject = @.subject,
> @.message = @.message,
> @.type = @.type,
> @.attachments = @.attachments,
> @.codepage = @.codepage,
> @.server = N'mail.cyber-village.net'
> select RC = @.rc
> go