T-SQL (SS2K8) :: Get Lowest Unused Value Of Nvarchar Field Being Used As Primary Key

Mar 21, 2014

Trying to get the lowest unused value of CrewID from the below table in a efficient manner. I cant change the table structure as its from a 3rd party and it would break our support agreement.

CREATE TABLE [dbo].[Crews](
[CrewID] [nvarchar](10) NOT NULL,
[CrewName] [nvarchar](200) NOT NULL,
[CompanyID] [nvarchar](10) NOT NULL,
[StartTime] [nvarchar](50) NULL,

[Code] .....

View 9 Replies


ADVERTISEMENT

T-SQL (SS2K8) :: Find Primary Key Table Name And Field Name Of Foreign Key

Apr 10, 2015

How can i find the primary field name and primary table name of a given foreign key.

For example

Table A:
IDa
Column1
Column2
Column3

Table B:
IDb
column1
column2
column3 <---- this is foreign key to table A's IDa

What i want to do is i pass input of tableB, column3 and i get name of Primary tableA and field name IDa. How is it possible to do in tsql ?

View 4 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

T-SQL (SS2K8) :: How To Cast Source Column As Nvarchar

Jun 5, 2015

The source column is varchar(1) but i need this as nvarchar(1).. How can I cast this as NVARCHAR...

View 5 Replies View Related

T-SQL (SS2K8) :: Remove Non-numeric Values From A Nvarchar Column

Dec 9, 2014

We have an address table with a house_num field which is a nvarchar.

Most of house numbers are numbers like 1234, 0989

But some of them have a letter behind it like 678 B, 8909 F, even some like this 123/B

We would like to remove any non-numeric letter for this column.

Is there a way to do it?

View 4 Replies View Related

T-SQL (SS2K8) :: Store Result Of Stored Procedure Into XML / Nvarchar (max) Variable

Feb 16, 2012

I have a stored procedure that returns XML using FOR XML Explicit. I need to use the output of this procedure in another procedure, and modify the xml output before it is saved somewhere.

Say StoredProc1 is the one returning xml output and StoredProc2 needs to consume the output of StoredProc1

I declared a nvarchar(max) variable and trying to saved the result of StoredProc1

Declare @xml nvarchar(max)
EXEC @xml = StoredProc1 @Id

This doesn't work as expected as @xml doesn't get any value assigned or rather I would say

EXEC @xml = StoredProc1 @Id

outputs the entire xml whereas it should just save the xml in a variable.

View 7 Replies View Related

Order Of Nvarchar(50) Field

Jun 12, 2008

In my SQL 2005 database table Records, I have 3 fields, field1, field2, and field3 which are all nvarchar(50) fields. The value of field2 is something like this, MDB006-MD002-0004-3-2007. I would like to order this field but only use the 0004-3-2007 part of the field to order it. Is it possible to put the last 11 charachters (0004-3-2007) in another field and then order it using this new field?

View 8 Replies View Related

Paragraph In Nvarchar Field

Mar 1, 2008

i'm having following:


create table tbl_text
(id int,
sometext nvarchar(max)
)

insert into tbl_text (id, sometext) values (1, 'I have here paragraph
and here is another one,
and another
and another')


how can i tell sql server 2005 to give use all the paragraphs within sometext field?

View 5 Replies View Related

UTF-8 String In Nvarchar Field

Jun 8, 2007

Hi!
Is there any way to store UTF-8 encoded string in Nvarchar field? Or strings can be stored only in Unicode?

View 3 Replies View Related

What Matter Are There If I Always Set Big Length In Nvarchar Field?

Sep 29, 2006

There are two fieldsA1 nvarchar(30)A2 nvarchar(800)I know nvarchar field is alterable length, if I store a string mystring='abc' to A1 field or to A2 field, I think they use the same disk space, so I think it's always a good way to define a big length nvarchar field such as A3 nvarchar(4000) for any length string, becuase they always use the same disk space, is it right?

View 1 Replies View Related

How To Return UTF 8 String From Nvarchar Field

Mar 29, 2004

hi

i have connected my ms sql 2000 with C using ODBC

can u help me to return the utf 8 string from nvarchar field ??
how should i do it
please help!!!!!!!

View 6 Replies View Related

SQL Field Convert Nvarchar To Datetime

Dec 4, 2007

Hi everyone.

So as the subject says, I have a few fields that are nvarchar but hold date information. Most of these fields I have been able to move to datetime easiliy enough, simply by going into edit mode for the table and converting the fields to datetime. But 1 field is giving me problems I keep getting this error.
quote:- Unable to modify table.
Arithmetic overflow error converting expression to data type datetime.
The statement has been terminated.

I really dont know why I'm getting this error, but I"m assuming it may have to be something like one of the records may not be in date format. But I don't know if this is the case and I don't know how to locate where my problem is coming from.
Any guidance is greatly appreciated.

Thanks.

View 2 Replies View Related

Problem With Line Break From NVARCHAR Field

Sep 2, 2006

I have data saved in nvarchar field in SQL Server and I am displaying it using <= dbReader["my_field"] but even the three or four paragraphs comes as one paragragh and I don't know know where are my line breaks going?  

View 6 Replies View Related

Which Charset For Nvarchar Field In SQL 2005 Database?

Sep 26, 2006

Which charset for nvarchar field in SQL 2005 database? UTF-8, UTF-16...Does normal character such as A, B, C use double-byte in nvarchar field?

View 4 Replies View Related

Inserting A Hyphen (-) Into The 3rd Position Of A Nvarchar Field

Sep 13, 2004

I have a colum of numbers, which datatype is nvarchar;

157853
4389
1999999999556
4568987

I need to insert a hyphen, 3 spaces from the right (to left) My numbers would look like this:

157-853
4-389
1999999999-556
4568-987

...do I use the rtrim function ?...what would the syntax look like ?

Thank you

View 3 Replies View Related

Converting Date Field From Informix To SQL Nvarchar

Apr 13, 2004

I copying data from our Informix 7.2 database into SQL Server 2K using DTS but hitting errors during the process. There appears to be date data within Informix that will not convert properly when moving into SQL. Since the error is appearing at the 1.5million (approx.) record. I figured on changing from datetime to nvarchar. Works like a charm! :-)

My new problem is converting it back to datetime so I can query against the date without having to create scripts to parse the field.

The data in SQL currently looks like this -> 2000-11-29 (nvarchar(50))
I would like to have it -> 11/29/00 (datetime)

Any help is greatly appreciated!

JT


The goodness we share is rewarded twice!

View 10 Replies View Related

Scripting Field Conversion From Nvarchar To Datetime

Apr 19, 2004

What is the correct syntax to convert a field from nvarchar to datetime?

View 2 Replies View Related

Search String Field (nvarchar) For Unicode Characters

Nov 8, 2006

MS SQL 2000. Does anyone know how to find all rows where an nvarchar column contains a specific unicode character? Is it possible without creating a user defined function? Here's the issue. I have a table Expression (ExpID, ExpText) with values like 'x < 100' and 'y ≤ 200'. where the second example contains Unicode character 8804 [that is, nchar(8804)]. Because it's unicode, I don't seem to be able to search for it with LIKE or PATINDEX. These fail:
SELECT * FROM Expression WHERE ExpText LIKE '%≤%'   -- no recordsSELECT * FROM Expression WHERE PATINDEX('%≤%', ExpText)   -- no records
However, SELECT PATINDEX('%≤%', 'y ≤ 200')  will return 3.
Any suggestions? Thanks in advance.

View 3 Replies View Related

T-SQL (SS2K8) :: How To Insert Or Update Primary Key (int)

May 22, 2014

since ten years perhpas the society has a database with some table (person, country, and so on)since last years , the project manager decides to create a new database with some new design because before some information was save in one table well, the problem is when we pass all application to the new model we've notice that some id are not the same !

sample :

table Language old model
-------------------------
id frenchDescription english description
----------------------------------------
3 Anglais English
.....
......

table Language new model

id frenchDescription english description
-----------------------------------------
5 Anglais English
.....
.....

Alright , you can understand that the new model must be the same id => 3

my question is how to modify id on the table ?

View 4 Replies View Related

T-SQL (SS2K8) :: Search All Tables For Primary Key Value?

Feb 26, 2015

I found a few 'SearchAllTables' scripts out there to find a value in any table/column/row of any Database.

My problem is that none of these database search queries seem to look at primary key values.

The value I'm looking for is a primary key - I need to find all the other tables that have this primary key value.

how I could accomplish this?

View 2 Replies View Related

NULL Values To Sequential Number (The Field Is Nvarchar Datatype)

Jun 16, 2012

Ok I have upgraded my works database from a poorly designed Access database to a SQL database. The previous system allowed NULL values and duplicates to be inserted into a field that should NOT ALLOW NULL Values or duplicates. Therefore, this issue has now been moved across to my new system as I cannot set these constraints on the field that has multiple NULL values.

My solution would be to use a sequential operator, so whatever = NULL would be changed to a sequential number that us as administrators would know was a bogus number starting at something like = 999999900 counting up from that. There are only 250 records that would require updating.

To make things more interesting this field is not a integer type, its a Nvarchar type as its a Hardware ID. Both numerical and characters are require.

View 1 Replies View Related

Saving Carriage Return In A Nvarchar Field (SQL Server 2005)

Oct 26, 2006

Hi,

As you can see, I'm totally new at Sql Server.

I have a problem, I store text into a nvarchar field (could be a 200 or 20,000 characters long string), inside the text there are several carriage returns which I would like to preserve to later presentation, but when retreiving the data from sql server I got the "cr" as "?", also I opened the database from Sql Managment and all cr's were saved as "?".

What can I do to preserve the cr inside each field ?

Thanks in advance.

View 6 Replies View Related

T-SQL (SS2K8) :: Return Primary Key From (updated) Record Of Merge Statement

Apr 16, 2014

I'm using a Merge statement to update/insert values into a table. The Source is not a table, but the parameters from a Powershell script. I am not using the Primary Key to match on, but rather the Computer Name (FullComputerName).

I am looking on how-to return the Primary Key (ComputerPKID) of an updated record as "chained" scripts will require a Primary Key, new or used.As an aside: the code below does return the newly generated Primary Key of an Inserted record.

CREATE PROCEDURE [dbo].[usp_ComputerInformation_UPSERT](
@FullComputerName varChar(50) = NULL
,@ComputerDescription varChar(255) = NULL
,@ComputerSystemType varChar(128) = NULL
,@ComputerManufacturer varChar(128) = NULL

[code]....

View 4 Replies View Related

New Primary Key Field

Apr 12, 2001

Does anyone has an idea on creating a new field in a table with more then say 10000 rows already in that table, and making that new field as primary key field. None of the fields in that table are unique.

View 2 Replies View Related

Bit Field As Primary Key

Nov 10, 2000

Hey guys.
I just wanted to ask you a question? we are having a field declared
as BIT and we want that field to be unique..We are not able to declare
as a primary key..Is there anyway to declare as unique from the database
point of view?..please help us out in this issue and i'd appreciate that.

Andrew.

View 5 Replies View Related

Primary Key Field

Nov 10, 2003

Hi,

I want to find out the primary key field name of the table using system table information i.e. sysobjects, syscolumns etc.
I tried to find it out but it seems to be very complicated.
Could anybody help me in this regards?

Thanks in advance.
Prasanna.

View 3 Replies View Related

How To Get A New Value For A Primary Key Field

May 12, 2008

Hello,

I have an app that is connected to SQL 2005 express edition.
In the DB there is a table that has an auto incremental primary key
What I want is, I want to get a new value for that auto incremental field before sending the new record's date to the DB to be stored. So I can display the new record's ID in my app's interface

So is there something in SQL server like SEQUENCE in oracle.


Thanks in advance.

View 11 Replies View Related

How To Get The Primary Key From The Field Of The Row I've Just Inserted

Jan 4, 2005

I need to insert a row of data and return the value of the primary key id of the row.
I thought that something like this would work


int Key = (int)command.ExecuteScalar();


where command is SqlCommand object.

It doesn't work, maybe I've misunderstood the usage of ExecuteScalar.

View 1 Replies View Related

Multi-field Primary Key

Nov 28, 2005

I have a table (table1) that has a bunch of fields....[field1][field2][field3][field4][field5]None of these fields are unique, but if I combine them, then they areunique.I know there is a way to make multi-field primary keys, but when I tryI get an that field1 is not unique, which I already know,How can I make a multi-field primary key?thanks

View 2 Replies View Related

Using An Identity Field As Primary Key

Jul 20, 2005

I want to use the Identity field (increment 1,1) as a primary key andhave a unique constraint on my other field which is of type char.I am worried that related data in other tables may lose referntialintegrity if records in the ID table get messed up and need to bere-entered.Can you please advice on best way to do this. I definitely need anumeric id field because it makes the joins and queries so muchfaster.

View 9 Replies View Related

How To Auto Increment A Primary ID Field?

Oct 8, 2006

I was just wondering on a very simple database table with lets say a primary key set to columb ID and another columb lets say products, can you make the primary key automaticly increment its self whenever a new entry has been put in?For instance say I have this table set up with ID Being the primary KEY, Columb 1 = ID( INT ), Columb 2 = Products ( VarChar(50) ), and have the fields ID = 1, and products = my product.....and if a user inserts a new record say from a gridview or some sort of data entry the second ID Feild will automaticly be  2 and the products gets updated per user input.......I'm very sorry but I'm having a hard time putting this into words for some reason..umm basicly user adds something into the products feild and the ID field automaticly increments one number higher from the last one?ThanksAdam.

View 4 Replies View Related

Automating Incrementation In Primary Key ID Field

Sep 18, 2004

I'm really puzzled with this. I am new to using MS SQL and need help with the primary key. When I was using Access, I would open the database table and just enter values for the various columns, each time a new column was begun, the computer would insert a unique number there. OK, so now I am using visual studio to work on a SQL database. I created a new table and the first field I specified was "ID", I then chose it as the primary key. For default value, I tried both auto number and auto increment. These don't seem to work, as when I type values into fields and try to move to the next row, having left the ID field blank, I get an error which reads "String or Binary data may be truncated". What is going on, what do I need to do so the field automatically populates with an ID number... Some research sort of led me to the concept of a "trigger" to do this. Is this the approach. I was able to r-click on the table and I saw an option for "create trigger" or "new trigger"... How do I learn to do this, is there a generic trigger to do an auto increment of a primary key ID field?

View 2 Replies View Related

Duplicate Entry In A Primary Key Field

Jul 10, 2007

Hi everybody couldn't get through with saving my data on the table with two primary keys...

my table structure is this

pubidintUnchecked (primary key)
pubchar(1)Unchecked
publchar(1)Unchecked
pubcodechar(2)Unchecked (primary key)

a sample data is here

pubid pub publ pubcode

1 a b ab
1 b b bb
2 a b ab
2 b b bb


when i save this table modifying the pubid and pubcode as primary keys the following error displays...

Unable to create index 'PK_PUBS3'.
CREATE UNIQUE INDEX terminated because a duplicate key was found for index ID 1. Most significant primary key is '51'.
Could not create constraint. See previous errors.
The statement has been terminated.


what i understand is that on the primary key duplicates are not allowed how could i allow it?

thanks

View 7 Replies View Related







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