sql - Using CROSS JOIN -


i learning how use cross joins , can't see doing wrong 1 attempting.

what have pattern , numbers table.

number table:
numberid tinyint

pattern table:
patternid tinyint identity(1,1)
patternresult varchar(5)

i have inserted each row in number table 1 - 22.

at moment getting no results displayed. i want display patterns between numbers 0 - 5 (i can't include '0' in number table later on using table requires number beginning @ '1' 'number' table

e.g  0 - 0 0 - 1 0 - 2 0 - 3 0 - 4 0 - 5 1 - 0 1 - 1 1 - 2 1 - 3 1 - 4 1 - 5  etc 

what doing incorrectly cross join?

insert dbo.pattern(patternresult) select cast(n.numberid varchar (5)) + ' - ' + cast(nn.numberid varchar (5)) patternresult dbo.number n cross join dbo.number nn 

first, query insert. insert statements not return result sets.

so, question is, return?

select * dbo.pattern 

next, pattern has space 5 characters, using 3 ' - '. so, try making pattern can fit (by removing spaces):

insert dbo.pattern(patternresult)     select cast(n.numberid varchar (5)) + '-' + cast(nn.numberid varchar (5)) patternresult     dbo.number n cross join          dbo.number nn; 

finally, when using varchar() there no advantage making sizes small. might define field patternresult varchar(255) big enough result. when using char() small value important, because characters stored spaces.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -