public static void SendMailMessageAsync()
{
ThreadStart threadStart = delegate { SendMailMessage(); };
Thread thread = new Thread(threadStart);
thread.Start();
}
Thursday, July 24, 2008
Wednesday, July 23, 2008
?? operator in C#
I found this C# today it's rock !!
string thisIsANull = null;
string thisIsANullCheck = thisIsANull ?? "";
thisIsANullCheck is set to ""
string thisIsANull = null;
string thisIsANullCheck = thisIsANull ?? "";
thisIsANullCheck is set to ""
Friday, February 15, 2008
descending sorting in SortedList
by default when you add an element to SortedList it's added in ascending order, for descending for you have to use a small trick.
internal class DescendingComparer : IComparer
{
public int Compare(object x, object y)
{
try
{
return System.Convert.ToInt32(x).CompareTo(System.Convert.ToInt32(y)) * -1;
}
catch (Exception ex)
{
return x.ToString().CompareTo(y.ToString());
}
}
}
SortedList membersList = new SortedList(new DescendingComparer());
membersList.Add()
internal class DescendingComparer : IComparer
{
public int Compare(object x, object y)
{
try
{
return System.Convert.ToInt32(x).CompareTo(System.Convert.ToInt32(y)) * -1;
}
catch (Exception ex)
{
return x.ToString().CompareTo(y.ToString());
}
}
}
SortedList membersList = new SortedList(new DescendingComparer());
membersList.Add()
Monday, January 21, 2008
Tuesday, November 20, 2007
easy way to make money !!
One of my friends told me this, but i never though people are earning more than 25k USD for a day ??? idea is simple, buy credit say woth 500 USD, and exchange it against depreciating currencies... for an example $ is deprecating alot these days so, you can buy GBP against USD and exchange it then in real time basis. I brought 500 USD and made 750 USD in 5 mins !! ohh yeah in the demo mode ;) this grate software is "eToro".
Friday, October 26, 2007
Tuesday, October 23, 2007
How to write settings to App.config(Configuration in C# .NET 2.0)
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["IP"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
yeap this is the microsoft example. doesn't work at all. !!! dont get caught this never works. I was trying hours and hours,
use this class .
public enum ConfigFileType
{
WebConfig,
AppConfig
}
public class AppConfig : System.Configuration.AppSettingsReader
{
public string docName = String.Empty;
private XmlNode node = null;
private int _configType;
public int ConfigType
{
get
{
return _configType;
}
set
{
_configType = value;
}
}
public bool SetValue(string key, string value)
{
XmlDocument cfgDoc = new XmlDocument();
loadConfigDoc(cfgDoc);
// retrieve the appSettings node
node = cfgDoc.SelectSingleNode("//appSettings");
if (node == null)
{
throw new System.InvalidOperationException("appSettings section not found");
}
try
{
// XPath select setting "add" element that contains this key
XmlElement addElem = (XmlElement)node.SelectSingleNode("//add[@key='" + key + "']");
if (addElem != null)
{
addElem.SetAttribute("value", value);
}
// not found, so we need to add the element, key and value
else
{
XmlElement entry = cfgDoc.CreateElement("add");
entry.SetAttribute("key", key);
entry.SetAttribute("value", value);
node.AppendChild(entry);
}
//save it
saveConfigDoc(cfgDoc, docName);
return true;
}
catch
{
return false;
}
}
private void saveConfigDoc(XmlDocument cfgDoc, string cfgDocPath)
{
try
{
XmlTextWriter writer = new XmlTextWriter(cfgDocPath, null);
writer.Formatting = Formatting.Indented;
cfgDoc.WriteTo(writer);
writer.Flush();
writer.Close();
return;
}
catch
{
throw;
}
}
public bool removeElement(string elementKey)
{
try
{
XmlDocument cfgDoc = new XmlDocument();
loadConfigDoc(cfgDoc);
// retrieve the appSettings node
node = cfgDoc.SelectSingleNode("//appSettings");
if (node == null)
{
throw new System.InvalidOperationException("appSettings section not found");
}
// XPath select setting "add" element that contains this key to remove
node.RemoveChild(node.SelectSingleNode("//add[@key='" + elementKey + "']"));
saveConfigDoc(cfgDoc, docName);
return true;
}
catch
{
return false;
}
}
private XmlDocument loadConfigDoc(XmlDocument cfgDoc)
{
// load the config file
if (Convert.ToInt32(ConfigType) == Convert.ToInt32(ConfigFileType.AppConfig))
{
docName = ((Assembly.GetEntryAssembly()).GetName()).Name;
docName += ".exe.config";
}
else
{
// docName = System.Web.HttpContext.Current.Server.MapPath("web.config");
}
cfgDoc.Load(docName);
return cfgDoc;
}
}
==========================
Eg
AppConfig a = new AppConfig();
a.ConfigType = 1;
a.SetValue("IP", "123132123123");
============================
config.AppSettings.Settings["IP"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
yeap this is the microsoft example. doesn't work at all. !!! dont get caught this never works. I was trying hours and hours,
use this class .
public enum ConfigFileType
{
WebConfig,
AppConfig
}
public class AppConfig : System.Configuration.AppSettingsReader
{
public string docName = String.Empty;
private XmlNode node = null;
private int _configType;
public int ConfigType
{
get
{
return _configType;
}
set
{
_configType = value;
}
}
public bool SetValue(string key, string value)
{
XmlDocument cfgDoc = new XmlDocument();
loadConfigDoc(cfgDoc);
// retrieve the appSettings node
node = cfgDoc.SelectSingleNode("//appSettings");
if (node == null)
{
throw new System.InvalidOperationException("appSettings section not found");
}
try
{
// XPath select setting "add" element that contains this key
XmlElement addElem = (XmlElement)node.SelectSingleNode("//add[@key='" + key + "']");
if (addElem != null)
{
addElem.SetAttribute("value", value);
}
// not found, so we need to add the element, key and value
else
{
XmlElement entry = cfgDoc.CreateElement("add");
entry.SetAttribute("key", key);
entry.SetAttribute("value", value);
node.AppendChild(entry);
}
//save it
saveConfigDoc(cfgDoc, docName);
return true;
}
catch
{
return false;
}
}
private void saveConfigDoc(XmlDocument cfgDoc, string cfgDocPath)
{
try
{
XmlTextWriter writer = new XmlTextWriter(cfgDocPath, null);
writer.Formatting = Formatting.Indented;
cfgDoc.WriteTo(writer);
writer.Flush();
writer.Close();
return;
}
catch
{
throw;
}
}
public bool removeElement(string elementKey)
{
try
{
XmlDocument cfgDoc = new XmlDocument();
loadConfigDoc(cfgDoc);
// retrieve the appSettings node
node = cfgDoc.SelectSingleNode("//appSettings");
if (node == null)
{
throw new System.InvalidOperationException("appSettings section not found");
}
// XPath select setting "add" element that contains this key to remove
node.RemoveChild(node.SelectSingleNode("//add[@key='" + elementKey + "']"));
saveConfigDoc(cfgDoc, docName);
return true;
}
catch
{
return false;
}
}
private XmlDocument loadConfigDoc(XmlDocument cfgDoc)
{
// load the config file
if (Convert.ToInt32(ConfigType) == Convert.ToInt32(ConfigFileType.AppConfig))
{
docName = ((Assembly.GetEntryAssembly()).GetName()).Name;
docName += ".exe.config";
}
else
{
// docName = System.Web.HttpContext.Current.Server.MapPath("web.config");
}
cfgDoc.Load(docName);
return cfgDoc;
}
}
==========================
Eg
AppConfig a = new AppConfig();
a.ConfigType = 1;
a.SetValue("IP", "123132123123");
============================
Monday, October 22, 2007
weekend
It's been some time since my last post. Last weekend i spent most of the time watching One Tree Hill season 4. Nothing much interesting comparing to season 3 I guess. Brooke breaks up with Lucas, and move on with their life's.
Thursday, October 18, 2007
ClickOnce on Vista
I was assigned to check Richfocus on vista using ClickOnce installation. since we need administration rights on Vista pc to install keybordhooks, I deceied to use
inside the manifest.... after that lots of issues started
1. The requested operation requires elevation
2. Execution level requested by the application is not supported.
are two common error in this field.
When i googled it, it says due to some security issues, it's not allowed to have admin previlage user context inside.
only solution for this problem is to re-run the exe file using shell command. :)
hope you guys will not waste time on this.. !
inside the manifest.... after that lots of issues started
1. The requested operation requires elevation
2. Execution level requested by the application is not supported.
are two common error in this field.
When i googled it, it says due to some security issues, it's not allowed to have admin previlage user context inside.
only solution for this problem is to re-run the exe file using shell command. :)
hope you guys will not waste time on this.. !
Tuesday, October 16, 2007
Vista Crack
I wanted to install Vista 64 bit version on one of the testing PCs to test RichFocus. when i tried to apply the crack it fails. To make it work you have to disable "User Account Control (UAC)" which protects Registry, services ext,
Turn Off or Disable User Account Control (UAC) in Windows Vista
then you have to apply this crack :)
Turn Off or Disable User Account Control (UAC) in Windows Vista
then you have to apply this crack :)
Unicode bug in RichTextBox
i found this today so i though of blogging it. there is a bug in the "_doc.Append" in the extended richtextbox. you have to replace that from this to work
replace:
_doc.Append(_text.Replace("\n", @"\par "));
with this:
string Text = _text.Replace("\n", @"\par ");
char[] chars = Text.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if ((int)chars[i] > 256)
{
_doc.AppendFormat(@"\u" + ((int)chars[i]).ToString() + "?");
}
else
{
_doc.Append(chars[i].ToString());
}
}
replace:
_doc.Append(_text.Replace("\n", @"\par "));
with this:
string Text = _text.Replace("\n", @"\par ");
char[] chars = Text.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if ((int)chars[i] > 256)
{
_doc.AppendFormat(@"\u" + ((int)chars[i]).ToString() + "?");
}
else
{
_doc.Append(chars[i].ToString());
}
}
Thursday, October 04, 2007
top most control in .NET
well in VB 6 we had zorder? in .net it's not there any more. if you want to set the top most control you have to use Controls.SetChildIndex(control, 0)
Tuesday, October 02, 2007
System.InvalidOperationException:
if you get this error you are screwed !!. it causes at no point! you just get the error from no where. solution is simple ... remove all Application.DoEvents() from your application
System.InvalidOperationException: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).
at System.Threading.SynchronizationContextSwitcher.Undo()
at System.Threading.ExecutionContextSwitcher.Undo()
at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
System.InvalidOperationException: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).
at System.Threading.SynchronizationContextSwitcher.Undo()
at System.Threading.ExecutionContextSwitcher.Undo()
at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Thursday, September 27, 2007
Flash/Blinking Window in C#
[DllImport("user32.dll")]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
//Stop flashing. The system restores the window to its original state.
public const UInt32 FLASHW_STOP = 0;
//Flash the window caption.
public const UInt32 FLASHW_CAPTION = 1;
//Flash the taskbar button.
public const UInt32 FLASHW_TRAY = 2;
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
public const UInt32 FLASHW_ALL = 3;
//Flash continuously, until the FLASHW_STOP flag is set.
public const UInt32 FLASHW_TIMER = 4;
//Flash continuously until the window comes to the foreground.
public const UInt32 FLASHW_TIMERNOFG = 12;
///
/// Flashes a window until the window comes to the foreground
/// Receives the form that will flash
///
/// The handle to the window to flash
///whether or not the window needed flashing
public static bool FlashWindowEx(Form frm)
{
IntPtr hWnd = frm.Handle;
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;
return (FlashWindowEx(ref fInfo) == 0);
}
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
//Stop flashing. The system restores the window to its original state.
public const UInt32 FLASHW_STOP = 0;
//Flash the window caption.
public const UInt32 FLASHW_CAPTION = 1;
//Flash the taskbar button.
public const UInt32 FLASHW_TRAY = 2;
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
public const UInt32 FLASHW_ALL = 3;
//Flash continuously, until the FLASHW_STOP flag is set.
public const UInt32 FLASHW_TIMER = 4;
//Flash continuously until the window comes to the foreground.
public const UInt32 FLASHW_TIMERNOFG = 12;
///
/// Flashes a window until the window comes to the foreground
/// Receives the form that will flash
///
/// The handle to the window to flash
///
public static bool FlashWindowEx(Form frm)
{
IntPtr hWnd = frm.Handle;
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;
return (FlashWindowEx(ref fInfo) == 0);
}
Tuesday, September 11, 2007
"The search key was not found in any record." in dBase ?
i came up with this error "The search key was not found in any record." while reading a dbf file some time back. i was going thu microsoft support site and and they ask you to install some kind of patch that will never work. finally i found the solution
TEPS TO RESOLVE ISSUE:
========================
1. To Resolve that issue, In the Registry Editor, browse to the following
Registry key:
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Eng ines\Xbase
2. On the Right Pane, Click on Deleted.
3. Right-Click on the Deleted and click on Modify.
4. Change the entry from
0000 01
to
0000 00
4. Click OK.
5. Close the Registry and then open Access and the file imports fine.
special thanks to Amy Vargo.
TEPS TO RESOLVE ISSUE:
========================
1. To Resolve that issue, In the Registry Editor, browse to the following
Registry key:
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Eng ines\Xbase
2. On the Right Pane, Click on Deleted.
3. Right-Click on the Deleted and click on Modify.
4. Change the entry from
0000 01
to
0000 00
4. Click OK.
5. Close the Registry and then open Access and the file imports fine.
special thanks to Amy Vargo.
Monday, September 03, 2007
convert an object in to byte array or byte array to object
I was looking for a sample code snippet to convert an object in to byte array. finally i had to do it on my own.
public byte[] objectToByte(Object obj )
{
MemoryStream fs = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, obj);
return fs.ToArray() ;
}
catch (SerializationException e )
{
return null;
}
finally
{
fs.Close();
}
}
public object ByteArrayToObject(Byte[] Buffer )
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(Buffer);
try
{
return formatter.Deserialize(stream);
}
catch
{
return null;
}
}
public byte[] objectToByte(Object obj )
{
MemoryStream fs = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, obj);
return fs.ToArray() ;
}
catch (SerializationException e )
{
return null;
}
finally
{
fs.Close();
}
}
public object ByteArrayToObject(Byte[] Buffer )
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(Buffer);
try
{
return formatter.Deserialize(stream);
}
catch
{
return null;
}
}
Monday, August 20, 2007
how to check bcp.exe wheather faild or sucessful ?
i wanted to figure out a way to check whether failed or successful to update the operation as successfully or fails. it's simple all you have to do is read the exit code.
bcp.exe will return 1 if it fails, otherwise 0
bcp.exe will return 1 if it fails, otherwise 0
Friday, August 10, 2007
C# Language Specification
C# Language Specification, Version 3.0 Available for Review
http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/CSharp%20Language%20Specification.doc
http://download.microsoft.com/download/3/8/8/388e7205-bc10-4226-b2a8-75351c669b09/CSharp%20Language%20Specification.doc
How to create a stagging table ?
special thanks to Robert W. Marda
sp_CreateAndExecTableScript 'InterfaceTree', '_stagging', 0 , 1
CREATE PROCEDURE spCOMMS_CreateStaggingTable
(@TableName varchar(255) = '',
@TableNameExt varchar(255) = '',
@DisplayScript bit = 0,
@Exec bit = 0,
@NoPK bit = 0,
@PKOnly bit = 0,
@NoIndexes bit = 0,
@NoTable bit = 0
)AS
SET NOCOUNT ON
--Begin invalid entries for parameters section
--Test for empty entry
IF @TableName = ''
BEGIN
PRINT '@TableName is a required parameter.'
RETURN 1
END
--Test for source table
IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[' + @TableName + ']') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
PRINT 'Table ' + @TableName + ' not found.'
RETURN 2
END
--End invalid entries for parameters section
DECLARE @Query varchar (8000),
@DFQuery varchar(8000)
SET @Query = ''
SET @DFQuery = ''
--Begin building datetime value to be used to ensure primary key and index names are unique
DECLARE @DateTime varchar(20)
DECLARE @rawDateTime varchar(20)
SET @rawdatetime = CURRENT_TIMESTAMP
SET @DateTime = SUBSTRING(@rawDateTime, 5, 2) + LEFT(@rawDateTime, 3) + SUBSTRING(@rawDateTime, 8, 4)
IF SUBSTRING(@rawDateTime, 13, 1) = ' '
SET @DateTime = @DateTime + SUBSTRING(@rawDateTime, 14, 1)
ELSE
SET @DateTime = @DateTime + SUBSTRING(@rawDateTime, 13, 2)
SET @DateTime = LTRIM(@DateTime) + '_' + SUBSTRING(@rawDateTime, 16, 4)
--End building datetime value
--Begin creating temp tables
--temp table #TableScript is used to gather data needed to generate script that will create the table
IF @NoTable = 0 AND @PKOnly = 0
CREATE TABLE #TableScript (
ColumnName varchar (30),
DataType varchar(40),
Length varchar(4),
[Precision] varchar(4),
Scale varchar(4),
IsNullable varchar(1),
TableName varchar(30),
ConstraintName varchar(255),
DefaultValue varchar (255),
GroupName varchar(35),
collation sysname NULL,
IdentityColumn bit NULL
)
--temp table #IndexScript is used to gather data needed to generate script that will create indexes for table
CREATE TABLE #IndexScript (
IndexName varchar (255),
IndId int,
ColumnName varchar (255),
IndKey int,
UniqueIndex int
)
--End creating temp tables
--Begin filling temp table #TableScript
IF @NoTable = 0 AND @PKOnly = 0
BEGIN
INSERT INTO #TableScript (ColumnName, DataType, Length, [Precision], Scale, IsNullable, TableName,
ConstraintName, DefaultValue, GroupName, collation, IdentityColumn)
SELECT LEFT(c.name,30) AS ColumnName,
LEFT(t.name,30) AS DataType,
CASE t.length
WHEN 8000 THEN c.prec --This criteria used because Enterprise Manager delivers the length in parenthesis for these datatypes when using its scripting capabilities.
ELSE NULL
END AS Length,
CASE t.name
WHEN 'numeric' THEN c.prec
WHEN 'decimal' THEN c.prec
ELSE NULL
END AS [Precision],
CASE t.name
WHEN 'numeric' THEN c.scale
WHEN 'decimal' THEN c.scale
ELSE NULL
END AS Scale,
c.isnullable,
LEFT(o.name,30) AS TableName,
d.name AS ConstraintName,
cm.text AS DefaultValue,
g1a.groupname,
c.collation,
CASE
WHEN c.autoval IS NULL THEN 0
ELSE 1
END AS IdentityColumn
FROM syscolumns c
INNER JOIN sysobjects o ON c.id = o.id
LEFT JOIN systypes t ON t.xusertype = c.xusertype --the first three joins get column names, data types, and column nullability.
LEFT JOIN sysobjects d ON c.cdefault = d.id --this left join gets column default constraint names.
LEFT JOIN syscomments cm ON cm.id = d.id --this left join gets default values for default constraints.
LEFT JOIN sysindexes g1 ON g1.id = o.id --the left join for sysfilegroups and sysindexes with aliases g1 and g1a
LEFT JOIN sysfilegroups g1a ON g1.groupid = g1a.groupid --are for determining which file group the table is in.
WHERE o.name = @TableName
AND g1.id = o.id AND g1.indid in (0, 1) --these two conditions are to isolate the file group of the table.
END
--End filling temp table #TableScript
--Begin building create table and default value constraints scripts.
IF @NoTable = 0 AND @PKOnly = 0
BEGIN
SET @Query = 'if exists (select * from sysobjects where id = object_id(N' + '''[dbo].['
+ @TableName + @TableNameExt + ']''' + ') and OBJECTPROPERTY(id, N' + '''IsUserTable''' + ') = 1)'
+ CHAR(10) + 'drop table [dbo].[' + @TableName + @TableNameExt + ']'
+ CHAR(10) + 'GO'
+ CHAR(10) + CHAR(10) + 'CREATE TABLE [dbo].[' + @TableName + @TableNameExt + '] ('
DECLARE @DataType varchar(40),
@Length varchar(4),
@Precision varchar(4),
@Scale varchar(4),
@Isnullable varchar(1),
@DefaultValue varchar(255),
@GroupName varchar(35),
@ColumnName varchar(255),
@ConstraintName varchar(255),
@collation sysname,
@TEXTIMAGE_ON bit,
@IdentityColumn bit
SET @TEXTIMAGE_ON = 0
DECLARE ColumnName Cursor For
SELECT ColumnName
FROM #TableScript
OPEN ColumnName
FETCH NEXT FROM ColumnName INTO @ColumnName
WHILE (@@fetch_status = 0)
BEGIN
SELECT @DataType = DataType,
@Length = Length,
@Precision = [Precision],
@Scale = Scale,
@Isnullable = isnullable,
@DefaultValue = DefaultValue,
@ConstraintName = ConstraintName,
@collation = collation,
@IdentityColumn = IdentityColumn
FROM #TableScript
WHERE ColumnName = @ColumnName
IF @DefaultValue IS NOT NULL
BEGIN
IF @DFQuery = ''
SET @DFQuery = @DFQuery
+ CHAR(10) + CHAR(10) + 'ALTER TABLE [dbo].[' + @TableName + @TableNameExt + '] WITH NOCHECK ADD'
SET @DFQuery = @DFQuery
+ CHAR(10) + CHAR(9) + 'CONSTRAINT [DF_' + @TableName + @TableNameExt + '_'
+ @ColumnName + '_' + @DateTime + '] DEFAULT ' + @DefaultValue
+ ' FOR [' + @ColumnName + '],'
END
IF @DataType = 'text' OR @DataType = 'ntext'
SET @TEXTIMAGE_ON = 1
SET @Query = @Query
+ CHAR(10) + CHAR(9) + '[' + @ColumnName + '] [' + @DataType + ']'
IF @IdentityColumn = 1
SET @Query = @Query
+ ' IDENTITY (' + LTRIM(STR(IDENT_SEED(@TableName))) + ', ' + LTRIM(STR(IDENT_INCR(@TableName))) + ')'
IF @DataType = 'varchar' OR @DataType = 'nvarchar' OR @DataType = 'char' OR @DataType = 'nchar'
OR @DataType = 'varbinary' OR @DataType = 'binary'
SET @Query = @Query
+ ' (' + @Length + ')'
IF @DataType = 'numeric' OR @DataType = 'decimal'
SET @Query = @Query
+ ' (' + @Precision + ', ' + @Scale + ')'
IF @collation IS NOT NULL AND @DataType <> 'sysname' AND @DataType <> 'ProperName'
SET @Query = @Query
+ ' COLLATE ' + @collation
IF @Isnullable = '1'
SET @Query = @Query + ' NULL'
ELSE
SET @Query = @Query + ' NOT NULL'
FETCH NEXT FROM ColumnName INTO @ColumnName
IF @@fetch_status = 0
SET @Query = @Query + ', '
END
CLOSE ColumnName
DEALLOCATE ColumnName
SET @Query = @Query
+ CHAR(10) + ')'
--Assign file group name
SELECT DISTINCT @GroupName = GroupName
FROM #TableScript
IF @GroupName IS NOT NULL
SET @Query = @Query
+ ' ON [' + @GroupName + ']'
IF @TEXTIMAGE_ON = 1
SET @Query = @Query
+ ' TEXTIMAGE_ON [' + @GroupName + ']'
IF RIGHT(@DFQuery,1) = ','
SET @DFQuery = LEFT(@DFQuery, LEN(@DFQuery) - 1)
SET @Query = @Query
+ CHAR(10) + 'GO'
END
--End building create table and default value constraints scripts.
--Begin filling temp table #IndexScript.
INSERT INTO #IndexScript (IndexName, IndId, ColumnName, IndKey, UniqueIndex)
SELECT i.name,
i.indid,
c.name,
k.keyno,
(i.status & 2) --Learned this will identify a unique index from sp_helpindex
FROM sysindexes i
INNER JOIN sysobjects o ON i.id = o.id
INNER JOIN sysindexkeys k ON i.id = k.id AND i.indid = k.indid
INNER JOIN syscolumns c ON c.id = k.id AND k.colid = c.colid
WHERE o.name = @TableName
AND i.indid > 0 and i.indid < 255 --eliminates non indexes
AND LEFT(i.name,7) <> '_WA_Sys' --eliminates statistic indexes
--End filling temp table #IndexScript.
DECLARE @PK varchar(2),
@IndID int,
@IndexName varchar(255),
@IndKey int
SET @PK = ''
SET @IndKey = 1
SELECT DISTINCT @IndexName = IndexName,
@IndID = indid
FROM #IndexScript
WHERE LEFT (IndexName, 2) = 'PK'
--Begin creating primary key script.
IF @PKOnly = 1 OR (@NoTable = 1 AND @NoPK = 0)
BEGIN
SET @Query = '--Add Primary Key' + CHAR(10)
SET @PK = 'PK'
END
IF @NoPK = 0
BEGIN
IF @IndexName IS NOT NULL
BEGIN
SET @Query = @Query
+ CHAR(10) + CHAR(10) + 'ALTER TABLE [dbo].[' + @TableName + @TableNameExt + '] WITH NOCHECK ADD'
+ CHAR(10) + 'CONSTRAINT [PK_' + @TableName + @TableNameExt + @PK + '_' + @DateTime + '] PRIMARY KEY '
IF @IndID = 1
SET @Query = @Query
+ 'CLUSTERED'
ELSE
SET @Query = @Query
+ 'NONCLUSTERED'
SET @Query = @Query
+ CHAR(10) + '('
DECLARE @OldColumnName varchar(255)
SET @OldColumnName = 'none_yet'
WHILE @IndKey <= 16
BEGIN
SELECT @ColumnName = ColumnName
FROM #IndexScript
WHERE IndexName = @IndexName AND IndID = @IndID AND IndKey = @IndKey
IF @ColumnName IS NOT NULL AND @ColumnName <> @OldColumnName
BEGIN
SET @Query = @Query
+ CHAR(10) + '[' + @ColumnName + '],'
END
SET @OldColumnName = @ColumnName
SET @IndKey = @IndKey + 1
END
IF RIGHT(@Query,1) = ','
SET @Query = LEFT(@Query, LEN(@Query) - 1)
SET @Query = @Query
+ CHAR(10) + ')'
--Add file group name
IF @GroupName is not null
SET @Query = @Query
+ ' ON [' + @GroupName + ']'
SET @Query = @Query
+ CHAR(10) + 'GO'
END
END
--End creating primary key script.
--Add default value constraint script to main script.
IF @NoTable = 0 AND @PKOnly = 0
SET @Query = @Query
+ @DFQuery
+ CHAR(10) + 'GO'
--Begin building index script.
IF @NoIndexes = 0 AND @PKOnly = 0
BEGIN
IF @NoPK = 0
SET @Query = @Query
+ CHAR(10)
IF @NoTable = 1
SET @Query = @Query
+ '--Add Indexes' + CHAR(10)
ELSE
SET @Query = @Query
+ CHAR(10)
DECLARE @IndexNameOrig varchar(255),
@UniqueIndex int
DECLARE IndexName Cursor For
SELECT DISTINCT IndexName,
indid,
UniqueIndex
FROM #IndexScript
WHERE LEFT (IndexName, 2) <> 'PK' AND LEFT(IndexName, 4) <> 'hind'
OPEN IndexName
FETCH NEXT FROM IndexName INTO @IndexName, @IndID, @UniqueIndex
WHILE @@fetch_status = 0
BEGIN
SET @IndexNameOrig = @IndexName
IF RIGHT(@IndexName,2) = 'PM' OR RIGHT(@IndexName,2) = 'AM'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 5)
IF LEFT(RIGHT(@IndexName,10),1) = '_'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 10)
ELSE
IF LEFT(RIGHT(@IndexName,11),1) = '_'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 11)
ELSE
IF LEFT(RIGHT(@IndexName,12),1) = '_'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 12)
SET @Query = @Query
+ CHAR(10) + 'CREATE '
IF @IndID = 1
SET @Query = @Query
+ 'CLUSTERED '
IF @UniqueIndex <> 0
SET @Query = @Query
+ 'UNIQUE '
SET @Query = @Query
+ 'INDEX [' + @IndexName + '_' + @DateTime + '] ON [dbo].[' + @TableName + @TableNameExt + ']('
SET @IndKey = 1
SET @OldColumnName = 'none_yet'
WHILE @IndKey <= 16
BEGIN
SELECT @ColumnName = ColumnName
FROM #IndexScript
WHERE IndexName = @IndexNameOrig AND IndID = @IndID AND IndKey = @IndKey
IF @ColumnName IS NOT NULL AND @ColumnName <> @OldColumnName
BEGIN
SET @Query = @Query
+ '[' + @ColumnName + '],'
END
SET @OldColumnName = @ColumnName
SET @IndKey = @IndKey + 1
END
IF RIGHT(@Query,1) = ','
SET @Query = LEFT(@Query, LEN(@Query) - 1)
SET @Query = @Query + ')'
--Add file group name
IF @GroupName is not null
SET @Query = @Query
+ ' ON [' + @GroupName + ']'
SET @Query = @Query
+ CHAR(10) + 'GO' + CHAR(10)
FETCH NEXT FROM IndexName INTO @IndexName, @IndID, @UniqueIndex
END
CLOSE IndexName
DEALLOCATE IndexName
END
--End building index script.
DROP TABLE #IndexScript
IF @NoTable = 0 AND @PKOnly = 0
DROP TABLE #TableScript
IF @DisplayScript = 1
PRINT @Query
IF @Exec = 1
BEGIN
--This code needed to remark out all GO commands before executing the code in the variable @Query
SET @Query = REPLACE(@Query,CHAR(10) + 'GO', CHAR(10) + '--GO')
Exec (@Query)
END
RETURN 0
GO
sp_CreateAndExecTableScript 'InterfaceTree', '_stagging', 0 , 1
CREATE PROCEDURE spCOMMS_CreateStaggingTable
(@TableName varchar(255) = '',
@TableNameExt varchar(255) = '',
@DisplayScript bit = 0,
@Exec bit = 0,
@NoPK bit = 0,
@PKOnly bit = 0,
@NoIndexes bit = 0,
@NoTable bit = 0
)AS
SET NOCOUNT ON
--Begin invalid entries for parameters section
--Test for empty entry
IF @TableName = ''
BEGIN
PRINT '@TableName is a required parameter.'
RETURN 1
END
--Test for source table
IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[' + @TableName + ']') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
PRINT 'Table ' + @TableName + ' not found.'
RETURN 2
END
--End invalid entries for parameters section
DECLARE @Query varchar (8000),
@DFQuery varchar(8000)
SET @Query = ''
SET @DFQuery = ''
--Begin building datetime value to be used to ensure primary key and index names are unique
DECLARE @DateTime varchar(20)
DECLARE @rawDateTime varchar(20)
SET @rawdatetime = CURRENT_TIMESTAMP
SET @DateTime = SUBSTRING(@rawDateTime, 5, 2) + LEFT(@rawDateTime, 3) + SUBSTRING(@rawDateTime, 8, 4)
IF SUBSTRING(@rawDateTime, 13, 1) = ' '
SET @DateTime = @DateTime + SUBSTRING(@rawDateTime, 14, 1)
ELSE
SET @DateTime = @DateTime + SUBSTRING(@rawDateTime, 13, 2)
SET @DateTime = LTRIM(@DateTime) + '_' + SUBSTRING(@rawDateTime, 16, 4)
--End building datetime value
--Begin creating temp tables
--temp table #TableScript is used to gather data needed to generate script that will create the table
IF @NoTable = 0 AND @PKOnly = 0
CREATE TABLE #TableScript (
ColumnName varchar (30),
DataType varchar(40),
Length varchar(4),
[Precision] varchar(4),
Scale varchar(4),
IsNullable varchar(1),
TableName varchar(30),
ConstraintName varchar(255),
DefaultValue varchar (255),
GroupName varchar(35),
collation sysname NULL,
IdentityColumn bit NULL
)
--temp table #IndexScript is used to gather data needed to generate script that will create indexes for table
CREATE TABLE #IndexScript (
IndexName varchar (255),
IndId int,
ColumnName varchar (255),
IndKey int,
UniqueIndex int
)
--End creating temp tables
--Begin filling temp table #TableScript
IF @NoTable = 0 AND @PKOnly = 0
BEGIN
INSERT INTO #TableScript (ColumnName, DataType, Length, [Precision], Scale, IsNullable, TableName,
ConstraintName, DefaultValue, GroupName, collation, IdentityColumn)
SELECT LEFT(c.name,30) AS ColumnName,
LEFT(t.name,30) AS DataType,
CASE t.length
WHEN 8000 THEN c.prec --This criteria used because Enterprise Manager delivers the length in parenthesis for these datatypes when using its scripting capabilities.
ELSE NULL
END AS Length,
CASE t.name
WHEN 'numeric' THEN c.prec
WHEN 'decimal' THEN c.prec
ELSE NULL
END AS [Precision],
CASE t.name
WHEN 'numeric' THEN c.scale
WHEN 'decimal' THEN c.scale
ELSE NULL
END AS Scale,
c.isnullable,
LEFT(o.name,30) AS TableName,
d.name AS ConstraintName,
cm.text AS DefaultValue,
g1a.groupname,
c.collation,
CASE
WHEN c.autoval IS NULL THEN 0
ELSE 1
END AS IdentityColumn
FROM syscolumns c
INNER JOIN sysobjects o ON c.id = o.id
LEFT JOIN systypes t ON t.xusertype = c.xusertype --the first three joins get column names, data types, and column nullability.
LEFT JOIN sysobjects d ON c.cdefault = d.id --this left join gets column default constraint names.
LEFT JOIN syscomments cm ON cm.id = d.id --this left join gets default values for default constraints.
LEFT JOIN sysindexes g1 ON g1.id = o.id --the left join for sysfilegroups and sysindexes with aliases g1 and g1a
LEFT JOIN sysfilegroups g1a ON g1.groupid = g1a.groupid --are for determining which file group the table is in.
WHERE o.name = @TableName
AND g1.id = o.id AND g1.indid in (0, 1) --these two conditions are to isolate the file group of the table.
END
--End filling temp table #TableScript
--Begin building create table and default value constraints scripts.
IF @NoTable = 0 AND @PKOnly = 0
BEGIN
SET @Query = 'if exists (select * from sysobjects where id = object_id(N' + '''[dbo].['
+ @TableName + @TableNameExt + ']''' + ') and OBJECTPROPERTY(id, N' + '''IsUserTable''' + ') = 1)'
+ CHAR(10) + 'drop table [dbo].[' + @TableName + @TableNameExt + ']'
+ CHAR(10) + 'GO'
+ CHAR(10) + CHAR(10) + 'CREATE TABLE [dbo].[' + @TableName + @TableNameExt + '] ('
DECLARE @DataType varchar(40),
@Length varchar(4),
@Precision varchar(4),
@Scale varchar(4),
@Isnullable varchar(1),
@DefaultValue varchar(255),
@GroupName varchar(35),
@ColumnName varchar(255),
@ConstraintName varchar(255),
@collation sysname,
@TEXTIMAGE_ON bit,
@IdentityColumn bit
SET @TEXTIMAGE_ON = 0
DECLARE ColumnName Cursor For
SELECT ColumnName
FROM #TableScript
OPEN ColumnName
FETCH NEXT FROM ColumnName INTO @ColumnName
WHILE (@@fetch_status = 0)
BEGIN
SELECT @DataType = DataType,
@Length = Length,
@Precision = [Precision],
@Scale = Scale,
@Isnullable = isnullable,
@DefaultValue = DefaultValue,
@ConstraintName = ConstraintName,
@collation = collation,
@IdentityColumn = IdentityColumn
FROM #TableScript
WHERE ColumnName = @ColumnName
IF @DefaultValue IS NOT NULL
BEGIN
IF @DFQuery = ''
SET @DFQuery = @DFQuery
+ CHAR(10) + CHAR(10) + 'ALTER TABLE [dbo].[' + @TableName + @TableNameExt + '] WITH NOCHECK ADD'
SET @DFQuery = @DFQuery
+ CHAR(10) + CHAR(9) + 'CONSTRAINT [DF_' + @TableName + @TableNameExt + '_'
+ @ColumnName + '_' + @DateTime + '] DEFAULT ' + @DefaultValue
+ ' FOR [' + @ColumnName + '],'
END
IF @DataType = 'text' OR @DataType = 'ntext'
SET @TEXTIMAGE_ON = 1
SET @Query = @Query
+ CHAR(10) + CHAR(9) + '[' + @ColumnName + '] [' + @DataType + ']'
IF @IdentityColumn = 1
SET @Query = @Query
+ ' IDENTITY (' + LTRIM(STR(IDENT_SEED(@TableName))) + ', ' + LTRIM(STR(IDENT_INCR(@TableName))) + ')'
IF @DataType = 'varchar' OR @DataType = 'nvarchar' OR @DataType = 'char' OR @DataType = 'nchar'
OR @DataType = 'varbinary' OR @DataType = 'binary'
SET @Query = @Query
+ ' (' + @Length + ')'
IF @DataType = 'numeric' OR @DataType = 'decimal'
SET @Query = @Query
+ ' (' + @Precision + ', ' + @Scale + ')'
IF @collation IS NOT NULL AND @DataType <> 'sysname' AND @DataType <> 'ProperName'
SET @Query = @Query
+ ' COLLATE ' + @collation
IF @Isnullable = '1'
SET @Query = @Query + ' NULL'
ELSE
SET @Query = @Query + ' NOT NULL'
FETCH NEXT FROM ColumnName INTO @ColumnName
IF @@fetch_status = 0
SET @Query = @Query + ', '
END
CLOSE ColumnName
DEALLOCATE ColumnName
SET @Query = @Query
+ CHAR(10) + ')'
--Assign file group name
SELECT DISTINCT @GroupName = GroupName
FROM #TableScript
IF @GroupName IS NOT NULL
SET @Query = @Query
+ ' ON [' + @GroupName + ']'
IF @TEXTIMAGE_ON = 1
SET @Query = @Query
+ ' TEXTIMAGE_ON [' + @GroupName + ']'
IF RIGHT(@DFQuery,1) = ','
SET @DFQuery = LEFT(@DFQuery, LEN(@DFQuery) - 1)
SET @Query = @Query
+ CHAR(10) + 'GO'
END
--End building create table and default value constraints scripts.
--Begin filling temp table #IndexScript.
INSERT INTO #IndexScript (IndexName, IndId, ColumnName, IndKey, UniqueIndex)
SELECT i.name,
i.indid,
c.name,
k.keyno,
(i.status & 2) --Learned this will identify a unique index from sp_helpindex
FROM sysindexes i
INNER JOIN sysobjects o ON i.id = o.id
INNER JOIN sysindexkeys k ON i.id = k.id AND i.indid = k.indid
INNER JOIN syscolumns c ON c.id = k.id AND k.colid = c.colid
WHERE o.name = @TableName
AND i.indid > 0 and i.indid < 255 --eliminates non indexes
AND LEFT(i.name,7) <> '_WA_Sys' --eliminates statistic indexes
--End filling temp table #IndexScript.
DECLARE @PK varchar(2),
@IndID int,
@IndexName varchar(255),
@IndKey int
SET @PK = ''
SET @IndKey = 1
SELECT DISTINCT @IndexName = IndexName,
@IndID = indid
FROM #IndexScript
WHERE LEFT (IndexName, 2) = 'PK'
--Begin creating primary key script.
IF @PKOnly = 1 OR (@NoTable = 1 AND @NoPK = 0)
BEGIN
SET @Query = '--Add Primary Key' + CHAR(10)
SET @PK = 'PK'
END
IF @NoPK = 0
BEGIN
IF @IndexName IS NOT NULL
BEGIN
SET @Query = @Query
+ CHAR(10) + CHAR(10) + 'ALTER TABLE [dbo].[' + @TableName + @TableNameExt + '] WITH NOCHECK ADD'
+ CHAR(10) + 'CONSTRAINT [PK_' + @TableName + @TableNameExt + @PK + '_' + @DateTime + '] PRIMARY KEY '
IF @IndID = 1
SET @Query = @Query
+ 'CLUSTERED'
ELSE
SET @Query = @Query
+ 'NONCLUSTERED'
SET @Query = @Query
+ CHAR(10) + '('
DECLARE @OldColumnName varchar(255)
SET @OldColumnName = 'none_yet'
WHILE @IndKey <= 16
BEGIN
SELECT @ColumnName = ColumnName
FROM #IndexScript
WHERE IndexName = @IndexName AND IndID = @IndID AND IndKey = @IndKey
IF @ColumnName IS NOT NULL AND @ColumnName <> @OldColumnName
BEGIN
SET @Query = @Query
+ CHAR(10) + '[' + @ColumnName + '],'
END
SET @OldColumnName = @ColumnName
SET @IndKey = @IndKey + 1
END
IF RIGHT(@Query,1) = ','
SET @Query = LEFT(@Query, LEN(@Query) - 1)
SET @Query = @Query
+ CHAR(10) + ')'
--Add file group name
IF @GroupName is not null
SET @Query = @Query
+ ' ON [' + @GroupName + ']'
SET @Query = @Query
+ CHAR(10) + 'GO'
END
END
--End creating primary key script.
--Add default value constraint script to main script.
IF @NoTable = 0 AND @PKOnly = 0
SET @Query = @Query
+ @DFQuery
+ CHAR(10) + 'GO'
--Begin building index script.
IF @NoIndexes = 0 AND @PKOnly = 0
BEGIN
IF @NoPK = 0
SET @Query = @Query
+ CHAR(10)
IF @NoTable = 1
SET @Query = @Query
+ '--Add Indexes' + CHAR(10)
ELSE
SET @Query = @Query
+ CHAR(10)
DECLARE @IndexNameOrig varchar(255),
@UniqueIndex int
DECLARE IndexName Cursor For
SELECT DISTINCT IndexName,
indid,
UniqueIndex
FROM #IndexScript
WHERE LEFT (IndexName, 2) <> 'PK' AND LEFT(IndexName, 4) <> 'hind'
OPEN IndexName
FETCH NEXT FROM IndexName INTO @IndexName, @IndID, @UniqueIndex
WHILE @@fetch_status = 0
BEGIN
SET @IndexNameOrig = @IndexName
IF RIGHT(@IndexName,2) = 'PM' OR RIGHT(@IndexName,2) = 'AM'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 5)
IF LEFT(RIGHT(@IndexName,10),1) = '_'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 10)
ELSE
IF LEFT(RIGHT(@IndexName,11),1) = '_'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 11)
ELSE
IF LEFT(RIGHT(@IndexName,12),1) = '_'
SET @IndexName = LEFT(@IndexName, LEN(@IndexName) - 12)
SET @Query = @Query
+ CHAR(10) + 'CREATE '
IF @IndID = 1
SET @Query = @Query
+ 'CLUSTERED '
IF @UniqueIndex <> 0
SET @Query = @Query
+ 'UNIQUE '
SET @Query = @Query
+ 'INDEX [' + @IndexName + '_' + @DateTime + '] ON [dbo].[' + @TableName + @TableNameExt + ']('
SET @IndKey = 1
SET @OldColumnName = 'none_yet'
WHILE @IndKey <= 16
BEGIN
SELECT @ColumnName = ColumnName
FROM #IndexScript
WHERE IndexName = @IndexNameOrig AND IndID = @IndID AND IndKey = @IndKey
IF @ColumnName IS NOT NULL AND @ColumnName <> @OldColumnName
BEGIN
SET @Query = @Query
+ '[' + @ColumnName + '],'
END
SET @OldColumnName = @ColumnName
SET @IndKey = @IndKey + 1
END
IF RIGHT(@Query,1) = ','
SET @Query = LEFT(@Query, LEN(@Query) - 1)
SET @Query = @Query + ')'
--Add file group name
IF @GroupName is not null
SET @Query = @Query
+ ' ON [' + @GroupName + ']'
SET @Query = @Query
+ CHAR(10) + 'GO' + CHAR(10)
FETCH NEXT FROM IndexName INTO @IndexName, @IndID, @UniqueIndex
END
CLOSE IndexName
DEALLOCATE IndexName
END
--End building index script.
DROP TABLE #IndexScript
IF @NoTable = 0 AND @PKOnly = 0
DROP TABLE #TableScript
IF @DisplayScript = 1
PRINT @Query
IF @Exec = 1
BEGIN
--This code needed to remark out all GO commands before executing the code in the variable @Query
SET @Query = REPLACE(@Query,CHAR(10) + 'GO', CHAR(10) + '--GO')
Exec (@Query)
END
RETURN 0
GO
Monday, July 30, 2007
nice google search tip
Check this,
1. Go to Google
2. Click images
3. Type "flowers" or any other word.
4. You will get a page which is having full of images
5. Then delete the URL from the address bar and paste the below script
javascript:R= 0; x1=.1; y1=.05; x2=.25; y2=.24; x3= 1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI= document.images ; DIL=DI.length; function A(){for(i=0; i
1. Go to Google
2. Click images
3. Type "flowers" or any other word.
4. You will get a page which is having full of images
5. Then delete the URL from the address bar and paste the below script
javascript:R= 0; x1=.1; y1=.05; x2=.25; y2=.24; x3= 1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI= document.images ; DIL=DI.length; function A(){for(i=0; i
Subscribe to:
Posts (Atom)