Thursday, December 16, 2010

The difference between "#" and "." in CSS Files

I found this information on stackoverflow.com: basically if you have a style that you need to apply to more than one element, use the class. If it's something like a header that will be used only once, you can use the div id.

code in the webpage:
This will be red.
this will be blue.

code in the CSS file
#myRedText
{
color: red;
}

.blueText
{
color: blue;
}

Thursday, November 4, 2010

Turning off the "Identity" column for a table

There are times you may want to temporarily turn off the population of a PK column's use of the identity value. This could be especially useful during data migration.

SET IDENTITY_INSERT tablename ON
SET IDENTITY_INSERT tablename OFF

The ON/OFF is referring to the SQL statement's ability to insert identity column value. When you turn it ON - you're telling the script that you'll provide the identity column value (so it won't)!

Thursday, October 14, 2010

Working with Time Values in SQL Server

Given that you have a column that is a datetime or smalldatetime datatype and this your data (by the way, in Management Studio, I entered the time w/o the date specified it defaulted to "today"):
select [testtime] from TableName
Output:
2010-10-14 06:00:00
2010-10-14 08:00:00
2010-10-14 23:00:00

To display only the time portion, using a 12 hour clock use this sql:
SELECT substring(convert(varchar(20), [testtime], 9), 13, 5) --time
+ ' '
+ substring(convert(varchar(30), [testtime], 9), 25, 2) --am/pm
FROM TableName
Output:
6:00 AM
8:00 AM
11:00 PM

Wednesday, September 29, 2010

Formatting Dates in query output

In Oracle we'd use the to_char to nicely format a date in mm/dd/yyyy (or other) output. It's very nice because you can supply whatever date format you want, and it is easy to mix and match.

In SQL Server, you must memorize the date format you want. To format a date use this code for mm/dd/yyyy format:

select CONVERT(nvarchar,dob,101)

Wednesday, June 30, 2010

Alter column in SQL Server

Example:
alter table permitsystem.[dbo].[ProjectLandOwner]
alter column
LandOwnerBusinessName nvarchar(200)

Max Length of Data in a column

Use the datalength function to find the length of a "text" column in SQL Server.

To find the max length of a value in your column combine with the Max function.

select MAX( datalength(last_name))
from LP_COMMON.fpm.xAD_LANDOWNERS

Friday, June 25, 2010

Create Table as in SQL Server

select * into [new_table_name]from [table_name]

Tuesday, May 18, 2010

SSIS conversion issue

I had a weird error today. I had an Oracle source table, and a SQL Server Destination table, and got an error in the dataflow component for the OLE Destination. The error was for both columns for the table and was "Column [the column name] cannot convert between unicode and non-unicode string data types". All other tables in my data flow were converting just fine, so it was really a mystery.

This is the fix: in the OLE DB destination - right click and go to the Advanced Editor, go to the Input and Output Properties, click the Destination Input/External Columns. Each of the columns' data type was set to Unicode string [DT_WSTR] - I changed it to string[DT_STR], which is what the the other columns were set to. The "red x" on my destination immediately went away, and my package executed just fine!

I don't know what it was about that particular table that caused the problem...

SSIS DefaultCodePage Warning

I found this on an EMC Consulting blog - it fixed my warnings -

I've been trying to access data in Oracle from SSIS via OLE DB and was getting the following warning:

"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."

The fix is simple. Set AlwaysUseDefaultCodePage=TRUE on the offending OLE DB Source component and it works fine.

Tuesday, January 19, 2010

GridView "Select all” in Header

Sometimes it would be nice to have a “select all” feature for your grid check boxes. 

image

This can be easily accomplished using the header template of the grid view.

ASP.net code

<asp:GridView ID="gvTagEndorsementTypes" 
runat="server" AutoGenerateColumns="false" >
      
<Columns>                   
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<asp:LinkButton ID="lbSelectEndorsements" 
OnClick="ToggleEndorsements_Click" runat="server"> Select 
</asp:LinkButton>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="cbSelect" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
...
C# code
protected void ToggleEndorsements_Click(object sender, EventArgs e)
{
foreach (GridViewRow erow in gvTagEndorsementTypes.Rows)
{
CheckBox echeckbox = (CheckBox)erow.FindControl("cbSelect");
//see if the checkbox is checked.             
if (echeckbox.Checked)
{ echeckbox.Checked = false; }
else { echeckbox.Checked = true; }
}
}

Last Compile Date

To check the last date of compile for a SQL procedure use this query:

select modify_date
from sys.all_objects o
where o.type = 'P'
and lower(o.name) = 'theprocname'

Tuesday, January 12, 2010

EmptyDataTemplate in a GridView

You can use the EmptyDataTemplate in your gridviews to display a message when “no data is found”.  This is an alternative to using code to check the number of rows in the gridview and show/hiding some label to indicate this.  The EmptyDataTemplate goes before the column definitions.

<asp:GridView ID="gvAuthorityExemptions"

AutoGenerateColumns="false" GridLines="None"

runat="server" Width="100%"> 
      
<EmptyDataTemplate>

<asp:Label ID="lblNoData" runat="server">

No Exemptions for License/Authority

</asp:Label>

</EmptyDataTemplate> 
      
<Columns>

Wednesday, January 6, 2010

Formatting Dates in a GridView

To display a date in mm/dd/yyyy format in a GridView use the following (make sure the “MM” is capitalized, because “mm” = minutes)

<asp:TemplateField HeaderText="Trip Date" >

<ItemTemplate >
<%# Server.HtmlEncode( Eval("TripDate", "{0:MM/dd/yyyy}").ToString() ) %>
</ItemTemplate>
</asp:TemplateField>