Click here to Skip to main content
15,908,264 members
Home / Discussions / Database
   

Database

 
QuestionCursor issue Pin
AndyInUK3-Dec-09 23:28
AndyInUK3-Dec-09 23:28 
AnswerRe: Cursor issue Pin
Ashfield4-Dec-09 1:20
Ashfield4-Dec-09 1:20 
GeneralRe: Cursor issue Pin
AndyInUK4-Dec-09 1:28
AndyInUK4-Dec-09 1:28 
GeneralRe: Cursor issue Pin
Ashfield4-Dec-09 2:16
Ashfield4-Dec-09 2:16 
AnswerRe: Cursor issue Pin
Bassam Saoud4-Dec-09 10:41
Bassam Saoud4-Dec-09 10:41 
GeneralRe: Cursor issue Pin
Shameel4-Dec-09 23:42
professionalShameel4-Dec-09 23:42 
AnswerRe: Cursor issue Pin
RyanEK6-Dec-09 13:18
RyanEK6-Dec-09 13:18 
AnswerRe: Cursor issue [modified] Pin
Niladri_Biswas7-Dec-09 21:59
Niladri_Biswas7-Dec-09 21:59 
Hi,
Try to understand the output of NewId()

If I issue select NewId() the output will be something like
3B311450-65BB-4AF8-898B-0CD02C5086E2
.

It is a pure hyphenized alphanumeric charecter. If your destination table has the Id column as integer type, then you need to either change the column type from Integer to Varchar or you need to extract only the numeric values from NewId() for your future use.

I have created a sample for you. Look into that(id datatype is varchar) . I hope you will get some insight.

declare @tblSource table(id int identity, FirstName varchar(50),LastName varchar(50))
declare @tblDest table(id varchar(max) , FirstName varchar(50),LastName varchar(50))
insert into @tblSource 
	select 'firstname1', 'lastname1' union all
	select 'firstname2', 'lastname2' union all
	select 'firstname3', 'lastname3' union all
	select 'firstname4', 'lastname4' union all
	select 'firstname5', 'lastname5' 


Query:

insert into @tblDest (id,FirstName,LastName)
select NEWID(),FirstName,LastName 
from @tblSource 

select * from @tblDest


Output:

id	FirstName	LastName
D2A3D81C-F76E-44A4-9D47-83FBE4DDB76B	firstname1	lastname1
0B827C0E-EB68-43EA-A423-B10575EAF572	firstname2	lastname2
EB4DB402-3D8F-4C09-9E37-004CE37DE1FD	firstname3	lastname3
E6CE9239-1E95-4660-B5AC-00DBFEE28474	firstname4	lastname4
345F70CC-B957-41CC-977C-9FBA7A81E912	firstname5	lastname5


In case you need to strip out only the numbers, here is an example
declare @str varchar(max)
set @str = 'D2A3D81C-F76E-44A4-9D47-83FBE4DDB76B'
;with cte as(
select 1 as rn 
union all
select rn+1 from cte where rn<LEN(@str)),
cte2 as(
select rn,chars
from cte
cross apply(select SUBSTRING(@str,rn,1) chars)X
where chars like '%[0-9]%'
)
select numericData from (
select cast(chars as varchar(max))from cte2
for xml path(''))X(numericData)


Output:

numericData
23817644494783476


Smile | :)

Niladri Biswas

modified on Tuesday, December 8, 2009 4:12 AM

QuestionPerformance tip on multiple selects to retrieve alot of BLOBS? Pin
Thomas ST3-Dec-09 22:28
Thomas ST3-Dec-09 22:28 
AnswerRe: Performance tip on multiple selects to retrieve alot of BLOBS? Pin
Ashfield4-Dec-09 1:27
Ashfield4-Dec-09 1:27 
AnswerRe: Performance tip on multiple selects to retrieve alot of BLOBS? Pin
Bassam Saoud4-Dec-09 10:44
Bassam Saoud4-Dec-09 10:44 
QuestionAdding an Identity Later T-SQL Pin
Vimalsoft(Pty) Ltd3-Dec-09 21:17
professionalVimalsoft(Pty) Ltd3-Dec-09 21:17 
AnswerRe: Adding an Identity Later T-SQL Pin
Mycroft Holmes3-Dec-09 22:11
professionalMycroft Holmes3-Dec-09 22:11 
GeneralRe: Adding an Identity Later T-SQL Pin
Vimalsoft(Pty) Ltd4-Dec-09 0:49
professionalVimalsoft(Pty) Ltd4-Dec-09 0:49 
QuestionGeneral question on DB normalization Pin
Dewald3-Dec-09 20:59
Dewald3-Dec-09 20:59 
AnswerRe: General question on DB normalization Pin
Mycroft Holmes3-Dec-09 22:17
professionalMycroft Holmes3-Dec-09 22:17 
GeneralRe: General question on DB normalization Pin
Dewald3-Dec-09 22:44
Dewald3-Dec-09 22:44 
GeneralRe: General question on DB normalization Pin
Mycroft Holmes3-Dec-09 22:56
professionalMycroft Holmes3-Dec-09 22:56 
AnswerRe: General question on DB normalization Pin
i.j.russell4-Dec-09 1:19
i.j.russell4-Dec-09 1:19 
AnswerRe: General question on DB normalization Pin
Eddy Vluggen4-Dec-09 3:01
professionalEddy Vluggen4-Dec-09 3:01 
GeneralRe: General question on DB normalization Pin
Dewald4-Dec-09 3:07
Dewald4-Dec-09 3:07 
AnswerDB Normalization - Further reading Pin
David Mujica4-Dec-09 3:37
David Mujica4-Dec-09 3:37 
Question[Message Deleted] Pin
Uma J3-Dec-09 20:24
Uma J3-Dec-09 20:24 
AnswerRe: Exporting data from stored procedure to excel spreadsheets Pin
dan!sh 3-Dec-09 20:46
professional dan!sh 3-Dec-09 20:46 
QuestionExport records to excel from sql Pin
padmanabhan N3-Dec-09 19:17
padmanabhan N3-Dec-09 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.