Wednesday, November 26, 2008
Changing Crystalreport database connection at runtime
CrxReport.Database.Tables(1).ConnectionProperties.Item("User ID") = struser
CrxReport.Database.Tables(1).ConnectionProperties.Item("Initial Catalog") = strdatabase
CrxReport.Database.Tables(1).ConnectionProperties.Item("password") = strpassword
Thursday, November 20, 2008
insert word file into the current document
Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
Wednesday, November 19, 2008
Word macro to find and replace text with a image file
.ClearFormatting
.Text = fvalue
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
m_WordApp.Selection.InlineShapes.AddPicture _
filename:=(App.Path & "\ABC HMO_CA.jpg"), _
LinkToFile:=False, SaveWithDocument:=True
m_WordApp.Selection.Collapse wdCollapseEnd
Loop
End With
Monday, November 3, 2008
How to use CASE in ORDER BY?
The following script sorts upper case addresses alphabetically followed by address lines starting with digits and finally lower case or non-alpha characters:
Use AdventureWorks;
Go
Select
AddressLine1,
AddressLine2=isnull(AddressLine2,''),
City,
[State] = sp.StateProvinceCode,
PostalCode,
Country = cr.Name
From Person.[Address] a
Join Person.StateProvince sp
On a.StateProvinceID = sp.StateProvinceID
Join Person.CountryRegion cr
On sp.CountryRegionCode = cr.CountryRegionCode
Order by
(Case
When Ascii([AddressLine1]) between 65 and 90 then 0 -- Upper case alpha
When Ascii([AddressLine1]) between 48 and 57 then 1 -- Digits
Else 2
End), AddressLine1, City
Go
Partial results:
AddressLine1 | AddressLine2 | City | State | PostalCode | Country |
Adirondack Factory Outlet | Lake George | NY | 12845 | United States | |
Alderstr 1849 | Braunschweig | NW | 38001 | Germany | |
Alderstr 2577 | Poing | SL | 66041 | Germany | |
Alderstr 2646 | Saarlouis | SL | 66740 | Germany | |
Alderstr 27 | Offenbach | SL | 63009 | Germany |