locked
HJow can i modify a sql query with guids ? RRS feed

  • Question

  • User1253338400 posted

    I haVE 

    I have Select * from mytable join mytable1 on mytable.NAME = mytable1.NAME

    I want to change it to 

    Select * from (GUID) as mytable join (GUID as mytable1  on mytable.NAME = mytable1.NAME

    that is put a guid but keep the name of mytable  , but it seems it replaces all the mytable if i do a search ?

    thanks

    Thursday, September 24, 2020 12:04 AM

All replies

  • User-1330468790 posted

    Hi robby32,

     

    Could you please rephrase your problem?

    Sorry that I am not sure what your purpose is. Do you want to involve GUID in your table?

     

    If you directly use the modified sql query, obviously you will get an error message => Invalid object name 'GUID'.

    Select * from GUID as mytable join GUID as mytable1  on mytable.NAME = mytable1.NAME

    The correct way to use GUID in SQL server is to use NEWID() function which will generate a value of type "uniqueidentifier".

    Only if you specify the problem would we be able to target the problem and provide you with solutions.

    Thank you for understanding.

    Best regards,

    Sean

    Thursday, September 24, 2020 2:12 AM
  • User1253338400 posted

    I have a query 

    Select * from mytable join mytable1 on mytable.NAME = mytable1.NAME

    I want to change it to 

    Select * from NewId() as mytable join (NewId() as mytable1  on mytable.NAME = mytable1.NAME

    so only change the first mytable value and not the others but not the others

    Thursday, September 24, 2020 3:37 AM
  • User303363814 posted

    The 'as' keyword gives something a different name.  So, 

    NewId() as mytable

    means that you have a table whose name is a new GUID and you want to call it mytable.  This make no sense at all.

    Show us some real tables and some real data and tell us what result you are trying to achieve

    Thursday, September 24, 2020 8:03 AM