Sunday 28 August 2011

Search in NTEXT column in SQL


To search in a column in SQL whose DataType is NTEXT or NVARCHAR use the reserved word LIKE
See the Example Below 
use DBName
select
from dbo.TableName
where NTextFieldName LIKE 'Your Search Word or Sentence'



Insert Into Sql Table from Formatted Text File


use DBName
BULK INSERT  dbo.Table_1 FROM 'c:\textFileName.txt' 
WITH (      


      FIELDTERMINATOR = '\t', --Tab
      ROWTERMINATOR = 'q'      --Char 'q'
);

SQL server Cast and Print


DECLARE @VariableName varchar(30)
SET @VariableName = 'Ring'
BEGIN
   SELECT CAST(@VariableName as NVARCHAR(1))
 PRINT @VariableName;
END
GO
--------------------
out put:
R

SQL Loop through records and replace


use DB_Name
DECLARE @var_1 as nvarchar(300)
DECLARE @var_2 as int --DECLARE @VariableName as Variable DataType
                                              --You can DECLARE many variable seperated by comma
                                              --to add another variable to the previous declaration use this example
                                              --,
                                              --@Variable2 as char

                             
DECLARE cursor_ CURSOR FOR   --declare the cursor
SELECT    primary_key_column_name , column2         --write a correct select statmen
FROM dbo.TableName

OPEN cursor_      --Open the cursor
FETCH NEXT FROM cursor_ INTO @var_1, @var_2  -- filling the variables using the cursor
WHILE (@@FETCH_STATUS = 0)        --Looping through the cursor
  BEGIN                             --Write you code here to do what you want


if(@var_2='null' or @var_2='NULL' OR @var_2='Null')

   UPDATE dbo.Channels SET var_2=column_name_to_be_replaced_with
   WHERE primary_key_column_name=@var_1

   FETCH NEXT FROM cursor_ INTO @chanID_, @chanName_Ar_ --To move the cursor to the next row
  END
  CLOSE cursor_                       --You have to close the cursor
  DEALLOCATE cursor_                  --You have to free the memory

Thursday 25 August 2011

Read Arabic text file into Sql server 2008 table

*  Save your text file as "unuicode"
*  use ntext, nvarchar, nchar as Columns Datatypes

* The DB collation should be Arabic_100_CI_AS

use this query:


use DBname
BULK INSERT  dbo.TableName FROM 'c:\TextFileName.txt' 
WITH (    

      FIELDTERMINATOR = '\t',
      ROWTERMINATOR = 'q'    
);


\t: is the delimiter between columns
q: is the delimiter between rows

Sunday 7 August 2011

How to start GlassFish 3.0 at boot in windows?

You may want to start your GlassFish 3.0 Server automatically at windows boot (Start). to do that
Follow these instructions:

1) Go to the installation location and open the bin folder, this is the default bath
C:\glassfish3\bin

2) Double click on "asadmin.bat" file
3) Type "start-domain myDomain" and press enter
4) To create the windows service which starts the server automatically at windows boot
type the command " create-service" and the server domain which you want to create a service for it;
 " create-service myDomain" and press Enter.
5) You need to install the service on Windows
    I) open cmd and type "sc create domain1 start= auto binPath= C:\mapviewer11g_qs\glassfish3\glassfish\domains\domain1\bin\domain1Service.exe"


or II) use the following procedure
    a) go to .net framework C:\Windows\Microsoft.NET
    b) search about installutil.exe
    c) if their is no .net framework installed, you need to install .net 4 or later to
        find installutil.exe
    d) Copy the path of installutil.exe  and past it at the end of the "Path" system
        variable
    e) Open cmd as administrator and cd into the bin directory of the domain which you
        created a service for it and type installutil sericeName.exe and hit enter
     f) Restart your PC.
     g) Configure your Service from system services


See the following snapshot

















Congratulations, your server runs automatically

Note: to view all creating commands type "create" and press enter, and so on for any word
Mohammad Abu Hmead

How to start GlassFish 3.0 at boot time in windows?

You may want to start your GlassFish 3.0 Server automatically at windows boot (Start). to do that
Follow these instructions:

1) Go to the installation location and open the bin folder, this is the default bath
C:\glassfish3\bin

2) Double click on "asadmin.bat" file
3) Type "start-domain myDomain" and press enter
4) To create the windows service which starts the server automatically at windows boot
type the command "create-service" and the server domain which you want to create a service for it;
 "create-services myDomain" and press Enter.
4) Restart your PC.

See the following snapshot

















Congratulations, your server runs automatically

Note: to view all creating commands type "create" and press enter, and so on for any word
Mohammad Abu Hmead