Showing posts with label sqlserver. Show all posts
Showing posts with label sqlserver. Show all posts

Wednesday, March 28, 2012

Regarding auto increment of id in sql table

I currently working asp.net with c# and inserting data from webpage into sqlserver 2000 data table. I have an auto increment ID in a table. Let's say 10 are inserted. Then you delete those 10. You add another and the auto increment sets the id at 11. How can I get that table to start back to 0? Plz help me and give code for increment id programmatically using c#. Thanks in Adv,

if you execute Delete * from yourTbale then you will see what are seeing, Use Truncate instead of delete, eg, Truncate table yourTableName (this will delete all the rows from your table)

|||

I reset the autoincrement with this but I've never tried running it from a stored procedure.

DBCC CHECKIDENT(MyTempTable1,RESEED, 0)

You might have to go this route. "EXEC ('DBCC CHECKIDENT(MyTempTable1,RESEED,0)')"

Reg: SqlServer Data Type

Hi
Can you please explain the difference between Text and nText data type in
SqlServer and at what situation we have to use this.
Siva.ntext is national text and it is used for storing unicode data.
text is used for storing non-unicode data
ntext occupies twice the size for storing the same data as in text
ntext supports all characters defined in unicode standard.|||and this is from BOL.. if you had not already seen it.
Using Unicode Data
The Unicode specification defines a single encoding scheme for most
characters widely used in businesses around the world. All computers
consistently translate the bit patterns in Unicode data into characters usin
g
the single Unicode specification. This ensures that the same bit pattern is
always converted to the same character on all computers. Data can be freely
transferred from one database or computer to another without concern that th
e
receiving system will translate the bit patterns into characters incorrectly
.
One problem with data types that use 1 byte to encode each character is that
the data type can only represent 256 different characters. This forces
multiple encoding specifications (or code pages) for different alphabets suc
h
as European alphabets, which are relatively small. It is also impossible to
handle systems such as the Japanese Kanji or Korean Hangul alphabets that
have thousands of characters.
Each Microsoft? SQL Server? collation has a code page that defines what
patterns of bits represent each character in char, varchar, and text values.
Individual columns and character constants can be assigned a different code
page. Client computers use the code page associated with the operating syste
m
locale to interpret character bit patterns. There are many different code
pages. Some characters appear on some code pages, but not on others. Some
characters are defined with one bit pattern on some code pages, and with a
different bit pattern on other code pages. When you build international
systems that must handle different languages, it becomes difficult to pick
code pages for all the computers that meet the language requirements of
multiple countries. It is also difficult to ensure that every computer
performs the correct translations when interfacing with a system using a
different code page.
The Unicode specification addresses this problem by using 2 bytes to encode
each character. There are enough different patterns (65,536) in 2 bytes for
a
single specification covering the most common business languages. Because al
l
Unicode systems consistently use the same bit patterns to represent all
characters, there is no problem with characters being converted incorrectly
when moving from one system to another. You can minimize character conversio
n
issues by using Unicode data types throughout your system.
In Microsoft SQL Server, these data types support Unicode data:
nchar
nvarchar
ntext
Note The n prefix for these data types comes from the SQL-92 standard for
National (Unicode) data types.
Use of nchar, nvarchar, and ntext is the same as char, varchar, and text,
respectively, except that:
Unicode supports a wider range of characters.
More space is needed to store Unicode characters.
The maximum size of nchar and nvarchar columns is 4,000 characters, not
8,000 characters like char and varchar.
Unicode constants are specified with a leading N: N'A Unicode string'.
All Unicode data uses the same Unicode code page. Collations do not control
the code page used for Unicode columns, only attributes such as comparison
rules and case sensitivity.|||SivaprakashShanmugam a écrit :
> Hi
> Can you please explain the difference between Text and nText data type in
> SqlServer and at what situation we have to use this.
NTEXT is encoded as UNICODE wich use 2 byte per chars
TEXT is encoded as ASCII wich use 1 byte per chars
This mean :
1) the amount of data is double while using NTEXT so the perfs whyle
retrieving data will be slower
2) only NTEXT an be use simultaneously by many alphabets like latin,
gr, cyrilic, hebrew, japanese, chinese...
A +

> Siva.
Frédéric BROUARD, MVP SQL Server, expert bases de données et langage SQL
Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modélisation, tuning, optimisation
********************* http://www.datasapiens.com ***********************

Reg. MS SLQSRVER 2000 driver (sp 1) driver for jdbc

Hi
I am writing jsp pages on JRUN (DM2k MX) server connecting to MS SQLServer 2000 dbase. using
MS SQLServer 2000 driver for JDBC (SP 1).
Everything is working fine, except when I try to access the result set, ( which is storing my query results),
I have a JSP scriptlet as below
//successfully connect a
// exceutet the query a
// store the result in ResultSet rs
<%
while (rs.next())
{
%><option value=<%=rs.getString("DeptName")%></option><%
}
%>
Each time this code runs, it skips the first record. I tried placing the cursor before the first record , prior to entering the
while loop, by
1) rs.beforeFirst()
or
2)
if (rs.getRow() == 2)
{
rs.absolute(1);
//rs.first();
}
which should force it to goto the first record. but botjh 1 & 2 failed and the error was
MS SQLServer 2000 driver for jdbc do not support beforeFirst / First
How do I get around this problem? Is this a bug in the driver or am I missing something?
Thanks in advance
How exactly are you populating the resultset? Do you see the same behavior
from a standalone JDBC program? Below is a code snippet that connects to
Northwind database. It retrieves the data without skipping the first row:
Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
con = java.sql.DriverManager.getConnection(url, userName, password);
String query = "SELECT * from Customers";
//Option 1
PreparedStatement stmt = con.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
//Option 2
//Statement stmt = con.createStatement();
//ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{
System.out.println("Contact Name: " + rs.getString("ContactName"));
}
rs.close();
stmt.close();
con.close();
con=null;
Give this code a try to see if the behavior is the same. Do you see the
same behavior with JDBC SP2?
Carb Simien, MCSE MCDBA MCAD
Microsoft Developer Support - Web Data
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
| Thread-Topic: Reg. MS SLQSRVER 2000 driver (sp 1) driver for jdbc
| thread-index: AcQiWoPDPDw+LtmiRSmrZYKbSsks1w==
| X-WN-Post: microsoft.public.sqlserver.jdbcdriver
| From: "=?Utf-8?B?U3VtYUpEQkM=?=" <anonymous@.discussions.microsoft.com>
| Subject: Reg. MS SLQSRVER 2000 driver (sp 1) driver for jdbc
| Date: Wed, 14 Apr 2004 12:56:02 -0700
| Lines: 42
| Message-ID: <F9963AEF-09BA-428A-B5C9-12505D15AE9F@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.jdbcdriver
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.sqlserver.jdbcdriver:5891
| NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
| X-Tomcat-NG: microsoft.public.sqlserver.jdbcdriver
|
| Hi
I am writing jsp pages on JRUN (DM2k MX) server connecting to MS SQLServer
2000 dbase. using
MS SQLServer 2000 driver for JDBC (SP 1).
Everything is working fine, except when I try to access the result set, (
which is storing my query results),
I have a JSP scriptlet as below
//successfully connect a
// exceutet the query a
// store the result in ResultSet rs
<%
while (rs.next())
{
%><option value=<%=rs.getString("DeptName")%></option><%
}
%>
Each time this code runs, it skips the first record. I tried placing the
cursor before the first record , prior to entering the
while loop, by
1) rs.beforeFirst()
or
2)
if (rs.getRow() == 2)
{
rs.absolute(1);
//rs.first();
}
which should force it to goto the first record. but botjh 1 & 2 failed and
the error was
MS SQLServer 2000 driver for jdbc do not support beforeFirst / First
How do I get around this problem? Is this a bug in the driver or am I
missing something?
Thanks in advance
|
sql

Monday, March 26, 2012

Reg Split Funtion

Hi,

Is it possible to split the following value in sql server ?

I have the value like 25 Email Accounts,50 Email Accounts in my sqlserver database.
Here i need only the numeric value .ie 25,50.Is it possible? can any one give me the solution ..

I am using ASP.Net and C# backend is SQL Server 2000.

Thanks and Regards
ArulUse Regular expressions to remove all Non Numeric characters.

Reg JDBC MS sQLSERVer driver SP2

Hi
Has anyone used ResultSet.first(), ResultSet.beforeFirst(), ResultSet.AfterLast(), ResultSet.absolute(1) methods
in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
I am hving problems with it., as it keeps throwing the msg, SQLSERVER 2000 driver for JDBC - unsupported mehod error for all the above calls. I am using JRUN server on DM2k MX to run my JSP.
I would appreciate your replies,
Thanks
Suma
"SumaJDBC" <anonymous@.discussions.microsoft.com> wrote in message
news:015E27EC-8BFC-49B6-96FD-669661A86912@.microsoft.com...
> Hi
> Has anyone used ResultSet.first(), ResultSet.beforeFirst(),
ResultSet.AfterLast(), ResultSet.absolute(1) methods
> in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER
JDBC driver SP2 ?
> I am hving problems with it., as it keeps throwing the msg, SQLSERVER 2000
driver for JDBC - unsupported mehod error for all the above calls. I am
using JRUN server on DM2k MX to run my JSP.
> I would appreciate your replies,
> Thanks
> Suma
What do you not understand about the error message? The calls are not
supported by the driver. In general it is best to stay away from them
anyway, simply stick to next(). It will give you optimal performance and
works on all JDBC drivers.
Silvio Bierman
|||Hi silvio
Thanks for your reply. I did use next(), but I am having wierd problem with that . I have to construct a dropdown box
, populating it from the database table values.
I connect to the DB, retrieve the required column values into the result set rs.
As I display the values , the first record is always being skipped and it is always picking up from second record onwards. Now can now U understand why I need to place rs.beforeFirst(), prior to the starting of that while loop!
or is there any other way of doing this? I am new to this , thus would appreciate an expert advice!
here's my scriptlet after (connection to the Db and populatinf the ResultSet rs (using a javabean (db) class for this )
try{
//rs.beforeFirst();
while(rs.next()) {
%><option value=<%=rs.getString("DeptName")%></option><BR><%
}
} catch (Exception e) {
msg = e.getMessage();
out.println(msg);
}
%><% db.close();%></select>
|||"SumaJDBC" <anonymous@.discussions.microsoft.com> wrote in message
news:3D950D2F-8ACE-468E-97AD-A6D33DDCC897@.microsoft.com...
> Hi silvio
> Thanks for your reply. I did use next(), but I am having wierd problem
with that . I have to construct a dropdown box
> , populating it from the database table values.
> I connect to the DB, retrieve the required column values into the result
set rs.
> As I display the values , the first record is always being skipped and it
is always picking up from second record onwards. Now can now U understand
why I need to place rs.beforeFirst(), prior to the starting of that while
loop!
> or is there any other way of doing this? I am new to this , thus would
appreciate an expert advice!
> here's my scriptlet after (connection to the Db and populatinf the
ResultSet rs (using a javabean (db) class for this )
> try{
> //rs.beforeFirst();
> while(rs.next()) {
>
> %><option value=<%=rs.getString("DeptName")%></option><BR><%
> }
> } catch (Exception e) {
> msg = e.getMessage();
> out.println(msg);
> }
> %><% db.close(); %></select>
I have heard that problem previously several times and each time it was an
error in the application code that caused the behaviour. Using
ResultSet rs = ...;
while (rs.next()) //process current row
should work always. If it doesn't something is seriously broken and the
methods you mention can;t help you. I would suggest you post some actual
code that produces the behaviour.
Silvio Bierman
|||Hi Silvio,
As U suggested I tried to look into my code for possible logical errors, but couldnt find any,. So I am posting my code below:
Thanks in advance (again) for taking time to answer my queries.
Suma
// This is DbConnection.java, the bean class for getting the DBconnection and excecuting DB related methods
package BeanClasses;
import java.sql.*;
import java.io.*;
import java.lang.*;
public class DbConnection{
String dbURL = "jdbc:microsoft:sqlserver://sql1;databaseName=DEVPurContr";
String dbDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
private Connection dbCon;
public String temp;
public String getTemp() { return temp;
}
public void setTemp (String Temp){
this.temp = Temp;
}
public DbConnection() {
super();
/*try {
connect();
} catch (Exception e) { }*/
}
public boolean connect () throws Exception { //This functionis called first get a valid connection
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
dbCon = DriverManager.getConnection(dbURL,"webuser","webus er3070");
}
catch (Exception e) { System.out.println(e.getMessage());
}
return true;
}
public void close() throws SQLException {
dbCon.close();
}
public ResultSet execSQL (String sql) throws SQLException { //This function is called to retrive the result set
// String (sql) is supplied at the run time, which is my select statement and the returned
// result set.
Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r==null) ? null : r;
}
public int execUpdate (String sql ) throws SQLException {
Statement s = dbCon.createStatement ();
int r = s.executeUpdate (sql);
return (r==0) ? -1 : r ;
}
}
// Here's my import , where I am importing relevant java packages
<%@. page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.util.*,java.lang.*,java.io .*" errorPage="" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>
// Heres's JSP code (relevant part )
<tr><td class="RequiredDetail" style="text-align:left;"><span style="color:white; font-size:10px; font-weight:bolder"></span>
Enter Department Name
</td><td style="text-align:right;"><select name="DeptName"><%
ResultSet rs = null;
int i;
%><%
String msg;
db.connect(); // Call to the bean
try {
rs = db.execSQL("SELECT distinct DeptName FROM tblDepartment order by DeptName" ); // call to the bean
} catch(Exception e) {
msg = e.getMessage();
}
try{
//rs.beforeFirst();
while(rs.next()) {
out.println(rs.getString("DeptName"));
%><option value=<%=rs.getString("DeptName")%></option><BR><%
}
} catch (Exception e) {
msg = e.getMessage();
out.println(msg);
}
%><% db.close();%></select></td></tr>
|||As far is I can tell from this code there is no reason for the strange
behaviour. Have you tried running it in a normal application instead of a
JSP page (I have little experience with JSPs)? Have you compared such
results with running the same query from the Query Analyzer?
Silvio Bierman
|||Hi
Yes. I have run the query (thru JDBC) on regular java compiler. I have also done it on sql analyzer. In both cases the behavior is as exepected. But in JSP, when I use MS SQL Server JDBC driver. I get this odd results.
I still fail to understand why MS JDBC driver fails to support ResultSet.beforeFirst () and ResultSet.afterLast() functions?
Suma
|||te cuento que tengo el mismo problema con ResultSet.absolute(1) methods in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
pero se logra solucionar con el drive JnetDirect pero tienes que comprarlo yo se que esa no es la idea por favor ayudame si hallas la solucion
Gracias
************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
|||trivadeneira@.olade.org.ec wrote:

> te cuento que tengo el mismo problema con ResultSet.absolute(1) methods in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
> pero se logra solucionar con el drive JnetDirect pero tienes que comprarlo yo se que esa no es la idea por favor ayudame si hallas la solucion
>
> Gracias
Hola. Si un mtodo falla con el MS jdbc conductor libre,
usted debe esperar o antes de que ellos liberen a su
siguiente conductor, y esperen que sea fijado entonces,
o usted puede usar un producto comercial.
El DataDirect es el negocio que realmente hace el
JDBC conductor de MS., entonces usted debera intentar su
conductor. Esto mostrar si el siguiente conductor de
los MS ser fijado.

>
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
|||trivadeneira@.olade.org.ec wrote:

> te cuento que tengo el mismo problema con ResultSet.absolute(1) methods in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
> pero se logra solucionar con el drive JnetDirect pero tienes que comprarlo yo se que esa no es la idea por favor ayudame si hallas la solucion
>
> Gracias
Hola. Si un mtodo falla con el MS jdbc conductor libre,
usted debe esperar o antes de que ellos liberen a su
siguiente conductor, y esperen que sea fijado entonces,
o usted puede usar un producto comercial.
El DataDirect es el negocio que realmente hace el
JDBC conductor de MS., entonces usted debera intentar su
conductor. Esto mostrar si el siguiente conductor de
los MS ser fijado.

>
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...

Refreshing data in the cursor.

Hello everybody,

I wrote a stored procedure for SqlServer 2000 and i am using it for paging purpose.
The procedure is as follows :

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[OLAP_PagedRows]
(
@.SelectFields nVarchar(2000) =NULL,

@.GroupByFields nvarchar(1000) =NULL,

@.BaseTable varchar(100),

@.KeyColumn nvarchar(200)=NULL ,

@.JoinTables varchar(500) =NULL,

@.ConditionalClause varchar(1000) =NULL,

@.Pagesize int = 10,

@.PageNumber int =1,

@.SortExpression nvarchar(200)=NULL,

@.SearchText nvarchar(200)=NULL

)

AS

BEGIN

DECLARE @.SQLSTMT NVarchar(4000)

DECLARE @.SQLSTMT1 NVarchar(4000)

SET @.SQLSTMT1 = ''

--check whether page size is given null or not, if so set to default value

IF @.Pagesize IS NULL OR @.Pagesize = ''

BEGIN

SET @.Pagesize =10

END

--check whether page number is given null or not, if so set to default value

IF @.PageNumber IS NULL OR @.PageNumber = ''

BEGIN

SET @.PageNumber =1

END

--Start constructing the query --

SET @.SQLSTMT = 'SELECT '

SET @.SQLSTMT1 = 'DECLARE @.CountValue INT SELECT @.CountValue = count(*) From '+@.BaseTable

SET @.SQLSTMT = @.SQLSTMT + @.SelectFields + ' FROM '+@.BaseTable

If @.JoinTables Is Not Null

BEGIN

SET @.SQLSTMT = @.SQLSTMT + ' ' +@.JoinTables

SET @.SQLSTMT1 = @.SQLSTMT1 + ' ' +@.JoinTables

END

DECLARE @.StmtWhereClause nvarchar(500)

SET @.StmtWhereClause =''

Get where conditional clause

If (@.SearchText Is Not Null AND RTRIM(LTRIM(@.SearchText))<>'')

BEGIN

SET @.StmtWhereClause = @.StmtWhereClause + ' WHERE ' + @.SearchText

END

If @.ConditionalClause Is Not Null AND RTRIM(LTRIM(@.ConditionalClause))<>''

BEGIN

IF (@.StmtWhereClause <> '')

BEGIN

SET @.StmtWhereClause= @.StmtWhereClause + 'AND ' +@.ConditionalClause

END

ELSE

BEGIN

SET @.StmtWhereClause = @.StmtWhereClause + ' WHERE ' + @.ConditionalClause

END

END

SET @.SQLSTMT = @.SQLSTMT + @.StmtWhereClause

SET @.SQLSTMT1 = @.SQLSTMT1 + @.StmtWhereClause

If @.GroupByFields Is Not Null And RTRIM(LTRIM(@.GroupByFields))<>''

BEGIN

SET @.SQLSTMT = @.SQLSTMT + ' Group By ' +@.GroupByFields

SET @.SQLSTMT1 = @.SQLSTMT1 + ' Group By ' +@.GroupByFields

END

IF @.SortExpression Is Not Null AND RTRIM(LTRIM(@.SortExpression))<>''

BEGIN

SET @.SortExpression = LTRIM(RTRIM(' Order By '+ @.SortExpression))

SET @.SQLSTMT = @.SQLSTMT +' '+ @.SortExpression

SET @.SQLSTMT1 = @.SQLSTMT1 +' '+ @.SortExpression

END

SET @.SQLSTMT1= @.SQLSTMT1+' SELECT @.CountValue As MyRows '

--SELECT @.SQLSTMT1

--SELECT @.SQLSTMT

DECLARE @.StartRow INT

SET @.SQLSTMT = ' DECLARE temp_Cursor CURSOR SCROLL FOR '+@.SQLSTMT

EXECUTE SP_EXECUTESQL @.SQLSTMT

Open temp_Cursor

DECLARE @.RowCount INT

SET @.RowCount = 1

SET @.startRow = (@.PageSize * (@.PageNumber-1))+@.RowCount

--SELECT @.startRow as 'Current Row'

WHILE @.RowCount <= @.PageSize

BEGIN

--Select @.StartRow 'as @.StartRow'

FETCH ABSOLUTE @.startRow From temp_Cursor

SET @.RowCount= @.RowCount+1

SET @.StartRow = @.startRow + 1

END

deallocate temp_Cursor

EXECUTE SP_EXECUTESQL @.SQLSTMT1

END

It is working fine but I have problem with this kind of paging. I need to load the whole data into the cursor and i have to fetch records. The problem is that my table's contains more than Half a million records in it. If I have to load each time this cursor it will be a very big problem on the server side.

Probably it may not be a best solution, but sqlserver 2000 cannot provide more help than this. If I use sub-query for this like using Top <Number> it adversly effecting the nature of the data retrieval.

One solution that I am thinking is Load cursor once and whenever some updations performed on those tables from which cursor is getting data should be automatically reflect the changes.

Is this possible? Please help me.

Regards

Andy Rogers

hi Andy Rogers
why you use cursor with more data?
please try do'nt use cursor.
you can use temp table for sorting data.
if your data wholud'nt changes, you can use static data.
order on the 0.5 millions records has overloading on the sql server 2000.
sort your data and then use that with SELECT TOP X for best performance.
good luck

|||Because there is no "BOTTOM" command in the select, this is very tricky to do. This is how I have done it in the past.

I modified your code a little. They way you were doing it, returns 1 record set with 1 record for every record. This method returns all records in 1 recordset.

Basically it does a "SELECT TOP @.startRow+PageSize", so you get the smallest set from top to bottom, into a temp table, then deletes everything before the @.startRow and returns the rest. This is the best method I have found.

DECLARE @.SQLSTMT NVarchar(4000)
DECLARE @.SQLSTMT1 NVarchar(4000)

SET @.SQLSTMT1 = ''

--check whether page size is given null or not, if so set to default value

IF @.Pagesize IS NULL OR @.Pagesize = ''

BEGIN
SET @.Pagesize =10
END

--check whether page number is given null or not, if so set to default value

IF @.PageNumber IS NULL OR @.PageNumber = ''
BEGIN
SET @.PageNumber =1
END

DECLARE @.StartRow INT
SET @.startRow = (@.PageSize * (@.PageNumber-1))+ 1

--Start constructing the query --

SET @.SQLSTMT1 = 'DECLARE @.CountValue INT SELECT @.CountValue = count(*) From '+@.BaseTable

SET @.SQLSTMT = 'SELECT TOP ' + CAST(@.startRow+@.PageSize AS VARCHAR(10)) + ' IntRowNum = IDENTITY(int,1,1), '

SET @.SQLSTMT = @.SQLSTMT + @.SelectFields + ' INTO #temptable FROM '+@.BaseTable

If @.JoinTables Is Not Null
BEGIN
SET @.SQLSTMT = @.SQLSTMT + ' ' +@.JoinTables
SET @.SQLSTMT1 = @.SQLSTMT1 + ' ' +@.JoinTables
END

DECLARE @.StmtWhereClause nvarchar(500)

SET @.StmtWhereClause =''

Get where conditional clause

If (@.SearchText Is Not Null AND RTRIM(LTRIM(@.SearchText))<>'')

BEGIN
SET @.StmtWhereClause = @.StmtWhereClause + ' WHERE ' + @.SearchText
END

If @.ConditionalClause Is Not Null AND RTRIM(LTRIM(@.ConditionalClause))<>''
BEGIN
IF (@.StmtWhereClause <> '')
BEGIN
SET @.StmtWhereClause= @.StmtWhereClause + 'AND ' +@.ConditionalClause
END
ELSE
BEGIN
SET @.StmtWhereClause = @.StmtWhereClause + ' WHERE ' + @.ConditionalClause

END
END

SET @.SQLSTMT = @.SQLSTMT + @.StmtWhereClause

SET @.SQLSTMT1 = @.SQLSTMT1 + @.StmtWhereClause

If @.GroupByFields Is Not Null And RTRIM(LTRIM(@.GroupByFields))<>''
BEGIN
SET @.SQLSTMT = @.SQLSTMT + ' Group By ' +@.GroupByFields
SET @.SQLSTMT1 = @.SQLSTMT1 + ' Group By ' +@.GroupByFields
END

IF @.SortExpression Is Not Null AND RTRIM(LTRIM(@.SortExpression))<>''
BEGIN
SET @.SortExpression = LTRIM(RTRIM(' Order By '+ @.SortExpression))
SET @.SQLSTMT = @.SQLSTMT +' '+ @.SortExpression
SET @.SQLSTMT1 = @.SQLSTMT1 +' '+ @.SortExpression
END

SET @.SQLSTMT = @.SQLSTMT + ' DELETE FROM #temptable WHERE IntRowNum < ' + CAST(@.startRow AS VARCHAR(10)) + ' SELECT * FROM #temptable DROP TABLE #temptable '

SET @.SQLSTMT1= @.SQLSTMT1+' SELECT @.CountValue As MyRows '

--SELECT @.SQLSTMT1
--SELECT @.SQLSTMT

EXECUTE SP_EXECUTESQL @.SQLSTMT

EXECUTE SP_EXECUTESQL @.SQLSTMT1

Tuesday, March 20, 2012

referencing linked server in stored procedures

hello, i need to reference a table in a sqlserver instance from a
stored procedure in a different sqlserverinsctance... it's possible
reference the table from the stored procedure?
Did you try using full naming:
servername.database.owner.Tablename
MC
"hongo32" <hongo32es@.yahoo.com> wrote in message
news:1133304999.836436.40130@.g49g2000cwa.googlegro ups.com...
> hello, i need to reference a table in a sqlserver instance from a
> stored procedure in a different sqlserverinsctance... it's possible
> reference the table from the stored procedure?
>

referencing linked server in stored procedures

hello, i need to reference a table in a sqlserver instance from a
stored procedure in a different sqlserverinsctance... it's possible
reference the table from the stored procedure?Did you try using full naming:
servername.database.owner.Tablename
MC
"hongo32" <hongo32es@.yahoo.com> wrote in message
news:1133304999.836436.40130@.g49g2000cwa.googlegroups.com...
> hello, i need to reference a table in a sqlserver instance from a
> stored procedure in a different sqlserverinsctance... it's possible
> reference the table from the stored procedure?
>

referencing linked server in stored procedures

hello, i need to reference a table in a sqlserver instance from a
stored procedure in a different sqlserverinsctance... it's possible
reference the table from the stored procedure?Did you try using full naming:
servername.database.owner.Tablename
MC
"hongo32" <hongo32es@.yahoo.com> wrote in message
news:1133304999.836436.40130@.g49g2000cwa.googlegroups.com...
> hello, i need to reference a table in a sqlserver instance from a
> stored procedure in a different sqlserverinsctance... it's possible
> reference the table from the stored procedure?
>

Wednesday, March 7, 2012

ref mail error

when I attepmt to start SQL ServerAgent I get the
following error messages:
[298] SQLServer Error: 18456, Login failed for user 'sa'.
[SQLSTATE 28000]
[000] Unable to connect to server '(local)';
SQLServerAgent cannot start
In SQL ServerAgent properties my sa password is correct
and I get a similar error message when I select 'Use
Windows authentication' on the Server Conection tab, can
this be caused by a problem with my Service Startup
acount ?
> when I attepmt to start SQL ServerAgent I get the
> following error messages:
> [298] SQLServer Error: 18456, Login failed for user 'sa'.
> [SQLSTATE 28000]
> [000] Unable to connect to server '(local)';
> SQLServerAgent cannot start
> In SQL ServerAgent properties my sa password is correct
> and I get a similar error message when I select 'Use
> Windows authentication' on the Server Conection tab, can
> this be caused by a problem with my Service Startup
> acount ?
The Builtin\Administrators might have been removed as a sysadmin.
Hope this helps,
Eric Crdenas
SQL Server senior support professional

ref mail error

when I attepmt to start SQL ServerAgent I get the
following error messages:
[298] SQLServer Error: 18456, Login failed for user 'sa'.
[SQLSTATE 28000]
[000] Unable to connect to server '(local)';
SQLServerAgent cannot start
In SQL ServerAgent properties my sa password is correct
and I get a similar error message when I select 'Use
Windows authentication' on the Server Conection tab, can
this be caused by a problem with my Service Startup
acount ?> when I attepmt to start SQL ServerAgent I get the
> following error messages:
> [298] SQLServer Error: 18456, Login failed for user 'sa'.
> [SQLSTATE 28000]
> [000] Unable to connect to server '(local)';
> SQLServerAgent cannot start
> In SQL ServerAgent properties my sa password is correct
> and I get a similar error message when I select 'Use
> Windows authentication' on the Server Conection tab, can
> this be caused by a problem with my Service Startup
> acount ?
--
The Builtin\Administrators might have been removed as a sysadmin.
Hope this helps,
Eric Crdenas
SQL Server senior support professional

ref mail error

when I attepmt to start SQL ServerAgent I get the
following error messages:
[298] SQLServer Error: 18456, Login failed for user 'sa'.
[SQLSTATE 28000]
[000] Unable to connect to server '(local)';
SQLServerAgent cannot start
In SQL ServerAgent properties my sa password is correct
and I get a similar error message when I select 'Use
Windows authentication' on the Server Conection tab, can
this be caused by a problem with my Service Startup
acount ?> when I attepmt to start SQL ServerAgent I get the
> following error messages:
> [298] SQLServer Error: 18456, Login failed for user 'sa'.
> [SQLSTATE 28000]
> [000] Unable to connect to server '(local)';
> SQLServerAgent cannot start
> In SQL ServerAgent properties my sa password is correct
> and I get a similar error message when I select 'Use
> Windows authentication' on the Server Conection tab, can
> this be caused by a problem with my Service Startup
> acount ?
--
The Builtin\Administrators might have been removed as a sysadmin.
Hope this helps,
--
Eric Cárdenas
SQL Server senior support professional

Monday, February 20, 2012

Reduce SQLServer Wait Time

Hi,
I ran waittype procedure to for 10 mins to check the sqlserver waittype and
time and got the following result
wait type
wait time percentage
-- -- --
***total***
7086.0 100.0
CXPACKET
3254.0 45.9
LATCH_EX
3034.0 42.8
..
...
I just want to reduce the above wait types,any idea. Currently the max
degree of parallelism is 0 .
SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
Env:
SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with Hyper-Threading
Technology.
thanks
Latch_EX wait times usually indicate you are having a lot of memory pressure
and sql server has to spend a lot of time swapping data or procedure pages
in and out of memory. The cxpacket waits are most likely due to the fact
that your procs are too busy doing this and can't keep up with each other.
My guess is that the HT is getting in the way some. Bottom line is you can
probably use more ram but here are as few things to try and see if they
help. One is to turn off HT. Another is to change the MAXDOP at the server
level. Try 2 first and then 1 if that doesn't help. Why do you only have
1GB allocated to SQL Server if you have 2GB total? Try bumping it up a few
hundred MB and see if that helps some. How much procedure cache do you
have? Do you have lots of recompiles or plans that are not reused? If so
then work on plan reuse.
Andrew J. Kelly SQL MVP
"kris" <kpxus@.yahoo.com> wrote in message
news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I ran waittype procedure to for 10 mins to check the sqlserver waittype
and
> time and got the following result
> wait type
> wait time percentage
> ----
--
> -- -- --
> ***total***
> 7086.0 100.0
> CXPACKET
> 3254.0 45.9
> LATCH_EX
> 3034.0 42.8
> .
> ..
> I just want to reduce the above wait types,any idea. Currently the max
> degree of parallelism is 0 .
> SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
> Env:
> SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with
Hyper-Threading
> Technology.
> thanks
>
|||Andrew,
thanks for your suggestions, actually another application is running on the
sqlbox which is taking 150MB. I will change the settings as per your
suggestion and again i will check that.
thanks
kris
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:%23lys46obEHA.1152@.TK2MSFTNGP09.phx.gbl...
> Latch_EX wait times usually indicate you are having a lot of memory
pressure
> and sql server has to spend a lot of time swapping data or procedure pages
> in and out of memory. The cxpacket waits are most likely due to the fact
> that your procs are too busy doing this and can't keep up with each other.
> My guess is that the HT is getting in the way some. Bottom line is you
can
> probably use more ram but here are as few things to try and see if they
> help. One is to turn off HT. Another is to change the MAXDOP at the
server
> level. Try 2 first and then 1 if that doesn't help. Why do you only have
> 1GB allocated to SQL Server if you have 2GB total? Try bumping it up a
few
> hundred MB and see if that helps some. How much procedure cache do you
> have? Do you have lots of recompiles or plans that are not reused? If so
> then work on plan reuse.
> --
> Andrew J. Kelly SQL MVP
>
> "kris" <kpxus@.yahoo.com> wrote in message
> news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> and
> ----
> --
> Hyper-Threading
>
|||Other apps on the same box compete for the same resources and will add
complexity to what is the root cause. That can increase the risk of HT
being an issue as well. Another thing I forgot to mention is that if your
having issues with HT you may want to consider Win2003 as it handles HT and
more much better than 2000.
Andrew J. Kelly SQL MVP
"kris" <kpxus@.yahoo.com> wrote in message
news:e71CvCqbEHA.1652@.TK2MSFTNGP09.phx.gbl...
> Andrew,
> thanks for your suggestions, actually another application is running on
the[vbcol=seagreen]
> sqlbox which is taking 150MB. I will change the settings as per your
> suggestion and again i will check that.
> thanks
> kris
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23lys46obEHA.1152@.TK2MSFTNGP09.phx.gbl...
> pressure
pages[vbcol=seagreen]
fact[vbcol=seagreen]
other.[vbcol=seagreen]
> can
> server
have[vbcol=seagreen]
> few
so[vbcol=seagreen]
waittype[vbcol=seagreen]
> ----
fixed.
>

Reduce SQLServer Wait Time

Hi,
I ran waittype procedure to for 10 mins to check the sqlserver waittype and
time and got the following result
wait type
wait time percentage
----
-- -- --
***total***
7086.0 100.0
CXPACKET
3254.0 45.9
LATCH_EX
3034.0 42.8
.
..
I just want to reduce the above wait types,any idea. Currently the max
degree of parallelism is 0 .
SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
Env:
SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with Hyper-Threading
Technology.
thanksLatch_EX wait times usually indicate you are having a lot of memory pressure
and sql server has to spend a lot of time swapping data or procedure pages
in and out of memory. The cxpacket waits are most likely due to the fact
that your procs are too busy doing this and can't keep up with each other.
My guess is that the HT is getting in the way some. Bottom line is you can
probably use more ram but here are as few things to try and see if they
help. One is to turn off HT. Another is to change the MAXDOP at the server
level. Try 2 first and then 1 if that doesn't help. Why do you only have
1GB allocated to SQL Server if you have 2GB total? Try bumping it up a few
hundred MB and see if that helps some. How much procedure cache do you
have? Do you have lots of recompiles or plans that are not reused? If so
then work on plan reuse.
Andrew J. Kelly SQL MVP
"kris" <kpxus@.yahoo.com> wrote in message
news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I ran waittype procedure to for 10 mins to check the sqlserver waittype
and
> time and got the following result
> wait type
> wait time percentage
> ----
--
> -- -- --
> ***total***
> 7086.0 100.0
> CXPACKET
> 3254.0 45.9
> LATCH_EX
> 3034.0 42.8
> .
> ..
> I just want to reduce the above wait types,any idea. Currently the max
> degree of parallelism is 0 .
> SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
> Env:
> SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with
Hyper-Threading
> Technology.
> thanks
>|||Andrew,
thanks for your suggestions, actually another application is running on the
sqlbox which is taking 150MB. I will change the settings as per your
suggestion and again i will check that.
thanks
kris
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:%23lys46obEHA.1152@.TK2MSFTNGP09.phx.gbl...
> Latch_EX wait times usually indicate you are having a lot of memory
pressure
> and sql server has to spend a lot of time swapping data or procedure pages
> in and out of memory. The cxpacket waits are most likely due to the fact
> that your procs are too busy doing this and can't keep up with each other.
> My guess is that the HT is getting in the way some. Bottom line is you
can
> probably use more ram but here are as few things to try and see if they
> help. One is to turn off HT. Another is to change the MAXDOP at the
server
> level. Try 2 first and then 1 if that doesn't help. Why do you only have
> 1GB allocated to SQL Server if you have 2GB total? Try bumping it up a
few
> hundred MB and see if that helps some. How much procedure cache do you
> have? Do you have lots of recompiles or plans that are not reused? If so
> then work on plan reuse.
> --
> Andrew J. Kelly SQL MVP
>
> "kris" <kpxus@.yahoo.com> wrote in message
> news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> and
> ----
> --
> Hyper-Threading
>|||Other apps on the same box compete for the same resources and will add
complexity to what is the root cause. That can increase the risk of HT
being an issue as well. Another thing I forgot to mention is that if your
having issues with HT you may want to consider Win2003 as it handles HT and
more much better than 2000.
Andrew J. Kelly SQL MVP
"kris" <kpxus@.yahoo.com> wrote in message
news:e71CvCqbEHA.1652@.TK2MSFTNGP09.phx.gbl...
> Andrew,
> thanks for your suggestions, actually another application is running on
the
> sqlbox which is taking 150MB. I will change the settings as per your
> suggestion and again i will check that.
> thanks
> kris
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23lys46obEHA.1152@.TK2MSFTNGP09.phx.gbl...
> pressure
pages[vbcol=seagreen]
fact[vbcol=seagreen]
other.[vbcol=seagreen]
> can
> server
have[vbcol=seagreen]
> few
so[vbcol=seagreen]
waittype[vbcol=seagreen]
> ----
fixed.[vbcol=seagreen]
>

Reduce SQLServer Wait Time

Hi,
I ran waittype procedure to for 10 mins to check the sqlserver waittype and
time and got the following result
wait type
wait time percentage
----
-- -- --
***total***
7086.0 100.0
CXPACKET
3254.0 45.9
LATCH_EX
3034.0 42.8
.
..
I just want to reduce the above wait types,any idea. Currently the max
degree of parallelism is 0 .
SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
Env:
SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with Hyper-Threading
Technology.
thanksLatch_EX wait times usually indicate you are having a lot of memory pressure
and sql server has to spend a lot of time swapping data or procedure pages
in and out of memory. The cxpacket waits are most likely due to the fact
that your procs are too busy doing this and can't keep up with each other.
My guess is that the HT is getting in the way some. Bottom line is you can
probably use more ram but here are as few things to try and see if they
help. One is to turn off HT. Another is to change the MAXDOP at the server
level. Try 2 first and then 1 if that doesn't help. Why do you only have
1GB allocated to SQL Server if you have 2GB total? Try bumping it up a few
hundred MB and see if that helps some. How much procedure cache do you
have? Do you have lots of recompiles or plans that are not reused? If so
then work on plan reuse.
--
Andrew J. Kelly SQL MVP
"kris" <kpxus@.yahoo.com> wrote in message
news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I ran waittype procedure to for 10 mins to check the sqlserver waittype
and
> time and got the following result
> wait type
> wait time percentage
> ----
--
> -- -- --
> ***total***
> 7086.0 100.0
> CXPACKET
> 3254.0 45.9
> LATCH_EX
> 3034.0 42.8
> .
> ..
> I just want to reduce the above wait types,any idea. Currently the max
> degree of parallelism is 0 .
> SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
> Env:
> SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with
Hyper-Threading
> Technology.
> thanks
>|||Andrew,
thanks for your suggestions, actually another application is running on the
sqlbox which is taking 150MB. I will change the settings as per your
suggestion and again i will check that.
thanks
kris
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:%23lys46obEHA.1152@.TK2MSFTNGP09.phx.gbl...
> Latch_EX wait times usually indicate you are having a lot of memory
pressure
> and sql server has to spend a lot of time swapping data or procedure pages
> in and out of memory. The cxpacket waits are most likely due to the fact
> that your procs are too busy doing this and can't keep up with each other.
> My guess is that the HT is getting in the way some. Bottom line is you
can
> probably use more ram but here are as few things to try and see if they
> help. One is to turn off HT. Another is to change the MAXDOP at the
server
> level. Try 2 first and then 1 if that doesn't help. Why do you only have
> 1GB allocated to SQL Server if you have 2GB total? Try bumping it up a
few
> hundred MB and see if that helps some. How much procedure cache do you
> have? Do you have lots of recompiles or plans that are not reused? If so
> then work on plan reuse.
> --
> Andrew J. Kelly SQL MVP
>
> "kris" <kpxus@.yahoo.com> wrote in message
> news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> > Hi,
> >
> > I ran waittype procedure to for 10 mins to check the sqlserver waittype
> and
> > time and got the following result
> >
> > wait type
> > wait time percentage
> ----
> --
> > -- -- --
> > ***total***
> > 7086.0 100.0
> > CXPACKET
> > 3254.0 45.9
> > LATCH_EX
> > 3034.0 42.8
> > .
> > ..
> > I just want to reduce the above wait types,any idea. Currently the max
> > degree of parallelism is 0 .
> > SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB fixed.
> >
> > Env:
> > SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with
> Hyper-Threading
> > Technology.
> >
> > thanks
> >
> >
>|||Other apps on the same box compete for the same resources and will add
complexity to what is the root cause. That can increase the risk of HT
being an issue as well. Another thing I forgot to mention is that if your
having issues with HT you may want to consider Win2003 as it handles HT and
more much better than 2000.
Andrew J. Kelly SQL MVP
"kris" <kpxus@.yahoo.com> wrote in message
news:e71CvCqbEHA.1652@.TK2MSFTNGP09.phx.gbl...
> Andrew,
> thanks for your suggestions, actually another application is running on
the
> sqlbox which is taking 150MB. I will change the settings as per your
> suggestion and again i will check that.
> thanks
> kris
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23lys46obEHA.1152@.TK2MSFTNGP09.phx.gbl...
> > Latch_EX wait times usually indicate you are having a lot of memory
> pressure
> > and sql server has to spend a lot of time swapping data or procedure
pages
> > in and out of memory. The cxpacket waits are most likely due to the
fact
> > that your procs are too busy doing this and can't keep up with each
other.
> > My guess is that the HT is getting in the way some. Bottom line is you
> can
> > probably use more ram but here are as few things to try and see if they
> > help. One is to turn off HT. Another is to change the MAXDOP at the
> server
> > level. Try 2 first and then 1 if that doesn't help. Why do you only
have
> > 1GB allocated to SQL Server if you have 2GB total? Try bumping it up a
> few
> > hundred MB and see if that helps some. How much procedure cache do you
> > have? Do you have lots of recompiles or plans that are not reused? If
so
> > then work on plan reuse.
> >
> > --
> > Andrew J. Kelly SQL MVP
> >
> >
> > "kris" <kpxus@.yahoo.com> wrote in message
> > news:OqCgT0obEHA.1248@.TK2MSFTNGP11.phx.gbl...
> > > Hi,
> > >
> > > I ran waittype procedure to for 10 mins to check the sqlserver
waittype
> > and
> > > time and got the following result
> > >
> > > wait type
> > > wait time percentage
> >
> ----
> > --
> > > -- -- --
> > > ***total***
> > > 7086.0 100.0
> > > CXPACKET
> > > 3254.0 45.9
> > > LATCH_EX
> > > 3034.0 42.8
> > > .
> > > ..
> > > I just want to reduce the above wait types,any idea. Currently the max
> > > degree of parallelism is 0 .
> > > SQL BOX has 2GB Memory and SQLServer is configured to use 1032MB
fixed.
> > >
> > > Env:
> > > SQL2000 + SP3 /Windows 2000 Advance Server 2 Processors with
> > Hyper-Threading
> > > Technology.
> > >
> > > thanks
> > >
> > >
> >
> >
>