Transact SQL :: Get Max Length Of All Nvarchars In A Database?

Jun 9, 2015

I am looking for a query that can search an entire database and return max length of all nvarchars in a database. I can write a cursor but its a pretty big database with  lots and lots of columns using nvarchars with most of them having a length of around 300 and doing a select max(len(nvarchar_col) from table from few tables return only 12 or 13. So I want to restrict the length of this data type accordingly.

View 9 Replies


ADVERTISEMENT

Transact SQL :: Increase Identifier Length

Dec 5, 2015

For example sake I removed the actual text, but this gets the point across as to what I want to do, but it throws this error

Msg 103, Level 15, State 4, Line 2
The identifier that starts with 'abc cde fghijkllmalama aljkjlkj alkjkljlkjkljk aljkljlkljk aljkascnalk alkjasdlkjlkajsd asdljklkasdjflkjasdf alkjasqquiouoie oiu' is too long. Maximum length is 128.

And this is my query

SELECT
GETDATE() As [abc cde fghijkllmalama aljkjlkj alkjkljlkjkljk aljkljlkljk aljkascnalk alkjasdlkjlkajsd asdljklkasdjflkjasdf alkjasqquiouoie oiuoiuoqq aoiuou!]

View 3 Replies View Related

Transact SQL :: Changing Length Of Datatype?

May 20, 2015

I have a field in a table

FormID nvarchar(6)

i want to change the length of the datatype to nvarchar(8).

what is the best way to do with out dropping the table?

View 5 Replies View Related

Transact SQL :: Length Of Column Values Mismatch

Jun 4, 2015

I have one column called ORGNAME NVarchar(34). There are two records which has the same value stored in that column"Mobile Payment Finland", in both records there are no spaces at start or end position, which mean both records are exactly same. But when i run

SELECT LEN(ORGNAME ) from table

it gives, 34 for first record and 22 for the second record. I couldnt understand what could be the exact problem.

If i use SELECT DATALENGTH(ORGNAME ) from table
then i get 68 and 44

View 8 Replies View Related

Transact SQL :: DATALength - Split A Field Based Off Its Length

May 15, 2015

I need to split a field based off it's length.  Initial thought was to take Left(field, characters), and Right(field, characters), but now I see I am duplicating the data as I am capturing too much of the data in.  However, what I actually need to achieve is in field1 capture the left 1000 characters, and in field 2 take from character 1001 to the end.  How can I update my syntax so that field2 will ONLY capture from character 1001 to end?

field1 = COALESCE(CASE WHEN DATALENGTH(exitinterviewnotes) > 998 THEN LEFT(CAST(exitinterviewnotes AS VARCHAR(MAX)), 1000) ELSE exitinterviewnotes END,''),
field2 = COALESCE(CASE WHEN DATALENGTH(exitinterviewnotes) > 998 THEN RIGHT(CAST(exitinterviewnotes AS VARCHAR(MAX)), 1000) END,'')

View 5 Replies View Related

Transact SQL :: Invalid Length Parameter Passed To Left Or Substring

Dec 1, 2015

is it possible to identify which value is causing me the above  error message and how to resolve it,These are for British postcodes.

create table #tmp (postcode varchar(200) NULL)
insert into #tmp values ('NULL')
insert into #tmp values ('-')
insert into #tmp values ('.')
insert into #tmp values ('0L6 7TP')
insert into #tmp values ('AB10 1WP')
insert into #tmp values ('AB51 5HH')

[code]...

This is the main query

select postcode,LEFT([Postcode], CHARINDEX(' ',[Postcode]) - 1)
from #tmp
order by Postcode
drop table #tmp

View 4 Replies View Related

Transact SQL :: Invalid Length Parameter Passed To LEFT Or SUB-STRING Function

Jul 22, 2015

when I am trying to perform below query,
 
  INSERT INTO EMPLOYEE
    SELECT TOP 100 *
 FROM EMPLOYEE_LANDING;

I am getting Invalid length parameter passed to the LEFT or SUBSTRING function.

View 3 Replies View Related

Peculiar Behavior In Stored Procedure (outputs Are Returning Proper Vals For Uniqueidentifiers And Ints, Not Nvarchars)

Apr 27, 2005

Rather than the real code, here's a sample we came up with.
 
Here's the C# Code:
public class sptest : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
private DataSet dtsData;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string strSP = "sp_testOutput";
SqlParameter[] Params = new SqlParameter[2];
Params[0] = new SqlParameter("@Input", "Pudding");
Params[1] = new SqlParameter("@Error_Text", "");
Params[1].Direction = ParameterDirection.Output;
try
{
this.dtsData = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["SIM_DSN"], CommandType.StoredProcedure, strSP, Params);
Label1.Text = Params[0].Value.ToString() + "--Returned Val is" + Params[1].Value.ToString();
}
//catch (System.Data.SqlClient.SqlException ex)
catch (Exception ex)
{
Label1.Text = ex.ToString();

}
}
 
Here is the stored procedure:
 
CREATE PROCEDURE [user1122500].[sp_testOutput](@Input nvarchar(76),@Error_Text nvarchar(10) OUTPUT)AS
SET @Error_Text = 'Test'GO
When I run this, it prints up the input variable, but not the output variable.

View 2 Replies View Related

T-SQL (SS2K8) :: Procedure Parameter Length Declaration Less Than Column Length?

Jun 30, 2014

is there any way or a tool to identify if in procedure the Parameter length was declarated less than table Column length ..

I have a table

CREATE TABLE TEST001 (KeyName Varchar(100) ) a procedure
CREATE PROCEDURE SpFindNames ( @KeyName VARCHAR(40) )
AS
BEGIN
SELECT KeyName FROM TEST001
WHERE KeyName = @KeyName
END
KeyName = @KeyName

Here table Column with 100 char length "KeyName" was compared with SP parameter "@KeyName" with length 40 char ..

IS there any way to find out all such usage on the ALL Procedures in the Database ?

View 2 Replies View Related

BlobColumn.GetBlobData() With Data Length &&> Integer Length (32767)

Mar 27, 2008

For those of you who would like to reference my exact issue, I'm dealing with the RSExecution SSIS package at the "Update Parameters" data flow task, at the Script Component.

The script tries to split parameter data into name and value. Unfortunately, I have several reports that are passing parameters that are very large. One example has over 65,000 characters all in the normal "&paramname=value&parm2=value..." format.

The code in the script works fine until it gets to one of these very large parameter sets. I have figured out what is causing the issue. Here's some code:

Dim paramBlob as Byte()
paramBlob = Row.BlobColumn.GetBlobData(0, Row.BlobColumn.Length)

The second parameter of the .GetBlobData function takes an INTEGER as its count! Therefore, no matter what kind of datatype I pass to the string that the script will later split, it will be limited to 32767 characters.

THIS IS A PROBLEM!!!

Does anyone know a workaround for this issue? I need all of the parameter data to be reported, and I would hate to have to skip over rows like this. Also, if I'm missing something, please fill me in!

Thanks for your help in advance,
LOSTlover

View 6 Replies View Related

Transact SQL :: Excel Data Import Truncate Data Length To 255

Jul 29, 2015

I am trying to import data from an excel Sheet to SQL Database using OPENROWSET. After import I found that all the cells containing data of more than 2000 length got truncated to  255 characters only. I tried finding the solution and found that We need to have the data with length more than 255 in first 8 rows of Excel sheet. It worked for me also. But In real scenario the data that I cant do the manual work on excel. I tried out with Dot Net utility and SSIS package also but the truncation is still the issue.

INSERT into tmp_Test
SELECT
*
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel
12.0;Database=D:Book1.xlsx', [Sheet1$])

View 9 Replies View Related

Transact SQL :: NVARCHAR Field Getting Truncated After Increasing Field Length?

Aug 28, 2015

I have a very strange situation. I've increased the size of an NVARCHAR field from 8 to 9 in a database table. The format of the data that I enter will either be an 8 character field (123456-8) or a 9 character field (1234567-9). The '-' is critical.

It used to only accept the 8 character version, but after increasing the field size, if I try to insert the 9 character field version, it gets truncated after the '-', as though it's still only allowing 8 characters. But that only occurs when I include the '-' or other such characters like '#'. If I try to insert 1234567a9, it works. The following explains the outcomes:

Inserted Value -> Result in table

123456-8 -> 123456-8      *Correct
1234567-9 -> 1234567-     *Wrong
123456789 -> 123456789    *Correct
1234567#9 -> 1234567#     *Wrong
1234567a9 -> 1234567a9    *Correct

Why is it that characters such as '-' and '#' are truncating the value, but only if the string is 9 chars long?

I'm currently using a direct t-sql insert statement in SQLExpress. The field is a simple NVARCHAR(9) field.

View 3 Replies View Related

Transact SQL :: Column Length Restriction When Naming CTE Column?

Jun 22, 2015

My CTE is failing and I don't know why...Is there a Common Table Expression column name length restriction???

View 2 Replies View Related

CommandParameters.length Don't Match Parametervalues.length

Feb 24, 2008

I am trying to narrow down this problem.  Basically, I added 3 columns to my article table.  It holds the article id, article text, author and so on.  I tested my program before adding the additional field to the program.  The program works fine and I can add an article, and edit the same article even though it skips over the 3 new fields in the database.  It just puts nulls into those columns.So, now I have added one of the column names I added in the database to the code. I changed my businesslogic article.vb code and the addarticle.aspx, as well as the New article area in the addartivle.aspx.vb  page. The form now has an additional textbox field for the ShortDesc which is a short description of the article. This is the problem now:  The command parameters.length is 9 and there are 10 parameter values.  Right in the middle of the 10 values is the #4 value which I inserted into the code.  It says Nothing when I hover my mouse over the code after my program throws the exception in 17 below.  Why is  command parameters.length set to 9 instead of 10?  Why isn't it reading the information for value 4 like all the other values and placing it's value there and calculating 10 instead of 9? Where are these set in the program?  Sounds to me like they are hard coded in someplace and I need to change them to match everything else.  1 ' This method assigns an array of values to an array of SqlParameters.2 ' Parameters:3 ' -commandParameters - array of SqlParameters to be assigned values4 ' -array of objects holding the values to be assigned5 Private Overloads Shared Sub AssignParameterValues(ByVal commandParameters() As SqlParameter, ByVal parameterValues() As Object)6 7 Dim i As Integer8 Dim j As Integer9 10 If (commandParameters Is Nothing) AndAlso (parameterValues Is Nothing) Then11 ' Do nothing if we get no data12 Return13 End If14 15 ' We must have the same number of values as we pave parameters to put them in16 If commandParameters.Length <> parameterValues.Length Then17 Throw New ArgumentException("Parameter count does not match Parameter Value count.") 18 End If19 20 ' Value array21 j = commandParameters.Length - 122 For i = 0 To j23 ' If the current array value derives from IDbDataParameter, then assign its Value property24 If TypeOf parameterValues(i) Is IDbDataParameter Then25 Dim paramInstance As IDbDataParameter = CType(parameterValues(i), IDbDataParameter)26 If (paramInstance.Value Is Nothing) Then27 commandParameters(i).Value = DBNull.Value28 Else29 commandParameters(i).Value = paramInstance.Value30 End If31 ElseIf (parameterValues(i) Is Nothing) Then32 commandParameters(i).Value = DBNull.Value33 Else34 commandParameters(i).Value = parameterValues(i)35 End If36 Next37 End Sub ' AssignParameterValues38 39 40 41  

View 2 Replies View Related

How Do I Find Data Having Max Length In The Database

May 18, 2006

How do I find data having max length in the Database ?

View 1 Replies View Related

Database Field Length Problem

Jul 20, 2005

Hi everyoneI had an access database running as the source for a website but ithas become too large to run correctly so it has been ported to MS-SQLthe problem is that 4 of the fields were Memo fields in access and assuch are 5000+ characters long each this overflows the allowed size onthe SQL server (8192)Is there a way round without splitting those 4 fields into seperatetales?? as this would cause a truly major re-write of the websiteThanks for any helpFurther details available if required

View 11 Replies View Related

SQL Server 2012 :: Limit The Length Of A Database Field?

Oct 27, 2014

How to limit the length of a database field such that only first 12 characters are shown in the result?

For example, I have show the only first 12 characters of employee name.

View 3 Replies View Related

Database Growth Excessive When Changing Varchar Length From 50 To 100.

Aug 9, 2007



Hi all,

I'm trying to get an understanding of a serious problem I have with a large DB in production. This is going to be obvious to someone (everyone probably) <bg>

I have a table which consists of numerous varchars and ints but also a Text type field. This table resides in a SQL 2000 Database. This DB currently has a data file size of 16Gb and a Transaction Log size of 17Gb. When I edit the table and increase the size of a Varchar field from 50 to 100 these files grow to more than double their size!

Why is this happening and how can I prevent this?

TIA

NozFx

View 1 Replies View Related

Transact SQL :: Finding Calling Database In A Sproc Called From A Different Database?

Apr 21, 2015

I'm trying to figure out how to identify the calling database within a sproc on a different database without using a parameter.

View 2 Replies View Related

Transact SQL :: Log All Changes In Database?

Sep 15, 2015

I want to find the best way to log all changes in my database. for example who changes which field and when it has been done.

View 6 Replies View Related

Alternatives To Use Database In Transact-sql

Feb 19, 2008

Are there other ways to change the database ?
For instance command stringdatabasename ?

View 2 Replies View Related

[TRANSACT]Can't Switch From Master To Another Database

Jul 23, 2005

Hello,I encounter a problem with a small portion of sqlcode. I try to go ondatabase using "use dbname" but i always stay in master. I executescript with the sa user.declare @dbnamesysnamedeclare @ret_codeintDECLARE db_cursor CURSOR FORselectnamefrommaster..sysdatabaseswherename not in ('master', 'model', 'tempdb', 'pubs', 'Northwind')-- Open cursorOPEN db_cursorFETCH NEXT FROM db_cursor INTO @dbnameWHILE @@FETCH_STATUS = 0BEGINexecute ('use ' + @dbname)execute ('select db_name()')Thank's for help,Pierrot.

View 2 Replies View Related

Transact SQL :: How To Find If A Column Is Used Anywhere In Database

Oct 20, 2015

I have looked around quite a bit, but mostly what I have found is looking to see if a table is used or if a column is in a stored procedure and honestly most of what I have seen does not work.

I want to reduce our nightly import by removing any columns that are not being used. We insert into our staging tables, Stage1 for example. And say Stage1 has column1 and column2. If those columns are not being used, then I want to remove them from Stage1. The only catch is that every Stage1 table has a v_Stage1. v_Stage1 should have all the columns from Stage1, but doesn't always. So I need to know what columns from Stage1 are used somewhere other than v_Stage1 and what columns from v_Stage1 are not used. 

View 14 Replies View Related

Transact SQL :: Script Has To Be Run Twice To Attach Database

Oct 26, 2015

SQL Server version: 2012 (11.0.5592) Standard

I have a script that runs the following SQL in order to attach a database.

if db_id('$(db_name)') IS NULL
BEGIN
CREATE DATABASE [$(db_name)] ON
(FILENAME = $(mdf_path)),
(FILENAME = $(ldf_path))
FOR ATTACH;
END

When I run the script, it executes without error. If I check the Windows Event log i see messages about database recovery and then finally 'Starting up database 'mydb''. Now when I open Management Studio the database is not there.

If I run the script again, and then refresh in Management Studio, the database now shows up. I've tried not running the script at all and just manually attaching the database via Management Studio.  I see the same messages in the Event log but this time, the database shows in Management Studio immediately. So my question is, why do I have to run the script twice?  I've tried waiting for 10 mins and then hitting refresh in Management Studio but the db never appears until i rerun the script.

View 4 Replies View Related

Transact SQL :: Updates Are Not Updating Database

Jun 12, 2015

No error is thrown, but the update is not made?  Possibly due to the dreaded inline sql being used?  The data structure for these 2 servers is horrific (but that is a story in itself).  The current structure (which needs immediate change) is each employee all 10 of them, have their own database.  If the userid is  6 or higher they are on server2 if the userid is 5 or below they are on server1.  Then they each have their own table that stores the data.  (A story for another day, but def needs overhaul).  However, here is the sql -- what needs to be altered to work with the current data structure and still get the updates needed?  Or we can scratch the update statements entirely if we can get the correct counts needed.

Declare
@employeeID varchar(50)
,@managerID varchar(50)
,@sql varchar(Max)
,@employee varchar(max)
,@itemsold varchar(max)

[Code] ....

View 13 Replies View Related

Transact SQL :: Want To Correct Database Design

Apr 29, 2015

I have below database already on one of the environment and its surprisingly designed somewhat in the past.now I want to correct it with one default filegroup with one primary and one log file, same time i am concerned for data as its production and no test environment is there, any way which ensure full consistency and steps i need to do...

CREATE
DATABASE [Sample]
ON 
PRIMARY
(
NAME =
N'Sample_Data',

[code]....

View 11 Replies View Related

Transact SQL :: Unable To Run Query From A Different Database?

Jul 14, 2015

I am trying to run a SQL query from a Different Datawarehouse DB on the same server but getting error: 

Msg 208, Level 16, State 1, Line 3
Invalid object name 'VirtualManagerDB.dbo.tbl_Cloud_CloudCapacity'.

My query is

select VM1.ID, VM1.VirtualCPUCount, VM1.Memory, VM1.Storage 
from [VirtualManagerDB].[dbo].[tbl_Cloud_CloudCapacity] AS VM1

Am running above query in a different database: OperationsManagerDW

View 5 Replies View Related

Transact SQL :: How To Compare Two Database Field

Sep 23, 2015

I have 2 database, databaseA and DatabaseB with same table structure.

I change lot of table structure in databaseB.

So i want compare what field that i add or delete in databaseB.

it's like what field there are in databaseB and not found in databaseA or nothing in databaseB but exist in databaseA.

How can i do that?

View 7 Replies View Related

Transact SQL :: Create A User For Only One Database

Jul 17, 2015

I have a Java application (APP) that use SQL Server 2008 - 20014. In the SQL server there can be more than my database. During setup of the database the first user (ex:ADM) is created using MS SQL Server Management Studio (SMS). ADM can then launch the APP with proper credentials and connect to the database.ADM can then, in the APP, create new users for the APP and database. After some testing for proper CREATE and GRANTS I use the following code to create a new Create, Read, Update, Delete (CRUD) user for the APP and database: CREATE LOGIN testuser WITH PASSWORD='password', DEFAULT_DATABASE = testdb

USE testdb
CREATE USER testuser FOR LOGIN testuser
GRANT AUTHENTICATE TO testuser WITH GRANT OPTION
GRANT CONNECT TO testuser WITH GRANT OPTION
GRANT ALTER ANY USER TO testuser WITH GRANT OPTION
GRANT CONNECT SQL TO testuser WITH GRANT OPTION
GRANT INSERT,SELECT,UPDATE, EXECUTE, DELETE TO testuser WITH GRANT OPTION

USE master
GRANT CONTROL SERVER TO testuser

USE testdb..When I the use the SMS and look at security the "testuser" is only added to testdb. To test I create a second database "testdb2" --> launch the APP to connect to testdb2 and can login with "testuser".I don't know if I give to much grants or missing one...proper TSQL so new users only have CRUD access to "testdb" and no other database on the SQL server.

View 5 Replies View Related

Transact SQL :: Remove Read Only From A Database?

Aug 26, 2011

i have a data base sql Server .I wrote a stored procedure or attach my database but it is attached in read only mode how can remove read-only.

this is my stored procedure.

create procedure attache
as
declare @trouvemdf int
declare @trouveldf int
if exists (select name from sysdatabases where name='Gestion_Parc')

[Code] ....

i try this EXEC sp_dboption 'Gestion_Parc', 'read only', 'FALSE' but it causes those error

Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C: Gestion_Parc.mdf". Operating system error 5: "5 (Access is denied.)".
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C: Gestion_Parc_log.ldf". Operating system error 5: "5 (Access is denied.)".
Msg 945, Level 14, State 2, Line 1

[Code] ....

View 3 Replies View Related

Transact SQL :: What Is Advantage Of Foreign Keys In Database

Apr 22, 2015

suppose if we do not have FK then what kind of advantage we could not avail. we can fetch data from two table by creating a relation in sql.....then why FK is required.

View 10 Replies View Related

Transact SQL :: Transaction On Alter Database Statement

Apr 20, 2015

Im working on Partition purge process, where I need to specify following statement:

SET @cmd = 'ALTER PARTITION FUNCTION ' + @function_name + '() MERGE RANGE (@range)'
EXEC (@cmd);
SET @cmd1 = 'ALTER DATABASE '+ db_name()+ ' REMOVE FILE ' + @partition_file
EXEC (cmd1);

I want to put this statement in Begin Tran /Commit statement but getting error that it is not allowed.  "ALTER DATABASE statement not allowed within multi-statement transaction"..what are my options to rollback in case there is a failure. 

View 4 Replies View Related

Transact SQL :: Query From Database From A Different Server And Domain

May 7, 2015

In my procedure I need to pull data from a database which is on other server and domain.

As usual I have used the below query but having troubles with mode of authentication.

SELECT * FROM OPENROWSET('SQLNCLI', 'Server=x.x.x.xsyz;Trusted_Connection=yes;','SELECT top 10 * FROM pcm.stats.visits') AS a

I get the below error:

"Login failed. The login is from an untrusted domain and cannot be used with Windows authentication"

I understand from the error that the domain and mode of authentication is different.

I use windows auth and we are given sql auth on the remote server which is on different domain.

I was suggested to use 'sp_addlinkserver' to link the remote server and query the data.

I am just curious to know if we can succeed through link server, is there any script to use sql authentication of remote server in my procedure and pull the data.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved